If the project has activities, this is the correct way to represent, differentiating the PUT
from PATCH
. Since I understand that there will be the /projetos/
feature and only /atividades/
for GET, I will organize the possible endpoints by HTTP methods.
GET
- Search all projects:
GET /projetos/
- Search for project number 1:
GET /projetos/1
- Search all project activities 1:
GET /projetos/1/atividades
- Search activity 1 of project 1:
GET /projetos/1/atividades/1
, but an option is also to create a /atividades/1
.
- Search activity 1:
GET /atividades/1
- Search all activities:
GET /atividades/
POST
- Create project number 1:
POST /projetos/
, passing in the request body the project information
- Create an activity in project number 1:
POST /projetos/1/atividades
, passing in the body of the request the activity information
You could also have a POST /atividades/1
, by passing the project number in the body. This decision will depend on how you want to represent the available resources. This "break" can be done when your endpoint gets too long or you think it will get better organized. If you choose to break, the ideal is to maintain consistency and also make the same break in other HTTP methods of the resource.
PUT
Used to replace an existing entire resource with another.
- Replace everything with the content of project number 1:
PUT /projetos/1
, passing in the body of the request all new project information
- Replace all an activity of number 1 in project number 1:
PUT /projetos/1/atividades/1
, passing in the body of the request 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 in the body of the request only the project information you would like to update
- Update any information from a number 1 activity in project number 1:
PATCH /projetos/1/atividades/1
, passing in the body of the request 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 with DELETE
of the database, which makes no sense.
Also remember return consistent HTTP codes . Example: 201 for creating a resource via POST
, 200 or 204 on PUT
and DELETE
, 404 for when not finding resource, etc.