If the project has activities, here is the correct way to represent, differentiating the PUT
of PATCH
. As I understand there will be the appeal /projetos/
and only the /atividades/
for GET, I will organize possible endpoints by HTTP methods.
GET
- Search all the projects:
GET /projetos/
- Fetch project number 1:
GET /projetos/1
- Browse all project activities 1:
GET /projetos/1/atividades
- Find Project 1 Activity 1:
GET /projetos/1/atividades/1
, but an option is also just to create a /atividades/1
.
- Search for activity 1:
GET /atividades/1
- Search all activities:
GET /atividades/
POST
- Create project number 1:
POST /projetos/
, passing on the request body the project information
- Create an activity in project number 1:
POST /projetos/1/atividades
, passing on the request body the activity information
You might as well have one POST /atividades/1
, passing the project number on the body. This decision will depend on how you want to represent the available resources. This "break" can be done when your endpoint starts to get too long or believes it will get better organized. If you are going to break, the ideal is to maintain consistency and also break the other HTTP methods of the resource.
PUT
Used to replace a resource whole existing on the other.
- Replace whole the contents of draft number 1:
PUT /projetos/1
, passing on the request body all new project information
- Replace all a number 1 activity in project number 1:
PUT /projetos/1/atividades/1
, passing on the request body the new activity information
PATCH
Used to change only one or some resource-specific information.
- Update any project information from number 1:
PATCH /projetos/1
, passing on the request body only the project information you would like to update
- Update any information from a number 1 activity in the number 1 project:
PATCH /projetos/1/atividades/1
, passing on the request body only the activity information
DELETE
- Remove project number 1:
DELETE /projetos/1
- Remove a number 1 activity in project number 1:
DELETE /projetos/1/atividades/1
.
The DELETE
can also be used when the sense is a logical exclusion of the resource, because sometimes the staff only associates this method to the DELETE
database, which makes no sense.
Also remember to return HTTP codes that are consistent. Example: 201 for creating a via resource POST
, 200 or 204 in PUT
and DELETE
, 404 for when not finding resource, etc.
I would like to add that Microsoft has published a Guideline for Apis, the content is available here: github.com/Microsoft/api-guidelines/
– Ronny Amarante