Skip to content

Commit e3ddd95

Browse files
added status code and example in get/post/put/delete methods
1 parent f8072ca commit e3ddd95

File tree

5 files changed

+73
-7
lines changed

5 files changed

+73
-7
lines changed

docs/rest-api/delete.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,21 @@ title: Delete Method
44
sidebar_label: Delete
55
---
66

7-
#### The following convention should be followed for Delete
7+
As the name applies, **DELETE** APIs are used to delete resources (identified by the Request-URI).
8+
9+
A successful response of DELETE requests SHOULD be HTTP response code 200 (OK) if the response includes an entity describing the status, 202 (Accepted) if the action has been queued, or 204 (No Content) if the action has been performed but the response does not include an entity.
10+
11+
DELETE operations are idempotent. If you DELETE a resource, it’s removed from the collection of resources. Repeatedly calling DELETE API on that resource will not change the outcome – however, calling DELETE on a resource a second time will return a 404 (NOT FOUND) since it was already removed. Some may argue that it makes the DELETE method non-idempotent. It’s a matter of discussion and personal opinion.
12+
13+
If the request passes through a cache and the Request-URI identifies one or more currently cached entities, those entries SHOULD be treated as stale. Responses to this method are not cacheable.
14+
15+
> * **/employees/{employee-id}**
16+
> * **/departments/{department-id}**
17+
18+
| Response code | Result/Reason |
19+
|---------------------------|------------------------------|
20+
|200 OK | Sucessfully deleted the Enity.|
21+
|401 (Unauthorized) | Invalid Credentials/ Invalid Authentication |
22+
|403 (Forbidden) | Invalid Authorization/ Insufficient rights/ Incorrect Role |
23+
|405 (Method Not allowed) | If API supports methods other than PUT request |
24+
|500 (Internal server error)| Server encountered an unexpected condition that prevented it from fulfilling the request.|

docs/rest-api/get.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ Use **GET requests** to retrieve resource representation/information only – an
1010
> * **/employees/{employee-id}/leaves**
1111
> * **/employees/{employee-id}/employee-reports**
1212
13+
Use query params to filter response or get subset or limited resource.
14+
15+
> * **/employees/{employee-id}/leaves?type={leave-type}&order-by={leave-date}**
16+
1317
| Response code | Result/Reason |
1418
|---------------------------|------------------------------|
1519
|200 OK | Sucessfully Fetched the Enity. <br/> Must include a response body. |

docs/rest-api/naming-convention.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,36 @@ In REST(**REpresentational State Transfer**), primary data **representation** is
1616

1717
> * **/customer/{customer-id}/check-validity**
1818
> * **/customer/{customer-id}/cart/checkout**
19+
20+
* Use forward slash (/) to indicate hierarchical relationships
21+
22+
> **/customers/{customer-id}/accounts/{account-id}/balance**
23+
> **/category/{cateogry-id}/products/{product-id}/balance**
24+
25+
* Do not use trailing forward slash (/) in URIs
26+
27+
> * **/employees** //Good practice
28+
> * **/employees/{employee-id}/leaves/** //Bad practice
29+
30+
* Use hyphens (-) to improve the readability of URIs
31+
32+
> * **/employees/{employee-id}/employee-reports** //Readable
33+
> * **/customer/{customer-id}/check-validity** //Readable
34+
>
35+
> * **/employees/{employee-id}/employeeReports** //Less Readable
36+
> * **/customer/{customer-id}/checkValidity** //Less Readable
37+
38+
* Do not use file extentions and underscores
39+
40+
> * **/employees/{employee-id}/employee-reports.pdf** /*Bad Practice*/
41+
> * **/employees/{employee-id}/employee_reports** /*Bad Practice*/
42+
43+
* Never use CRUD function names in URIs
44+
45+
URIs should not be used to indicate that a CRUD function is performed. URIs should be used to uniquely identify resources and not any action upon them. HTTP request methods should be used to indicate which CRUD function is performed.
46+
47+
> * GET Request **/employees** // Get all employees
48+
> * POST Request **/employees** // Create new employees
49+
> * GET Request **/employees/{employee-id}** // Get one employee with given id
50+
> * PUT Request **/employees/{employee-id}** // Update one employee with given id
51+
> * DELETE Request **/employees/{employee-id}** // Delete one employee with given id

docs/rest-api/post.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,15 @@ sidebar_label: Post
77
Use **POST requests** to create new subordinate resources, e.g., a file is subordinate to a directory containing it or a row is subordinate to a database table. Talking strictly in terms of REST, POST methods are used to create a new resource into the collection of resources.Note that POST is **neither safe nor idempotent**, and invoking two identical POST requests will result in two different resources containing the same information (except resource ids).
88

99
> * **/employees**
10-
> * **/employees/{employee-id}/leaves**
11-
> * **/employees/{employee-id}/employee-reports**
10+
> * **/departments**
1211
1312
| Response code | Result/Reason |
1413
|---------------------------|------------------------------|
15-
|201 OK | Sucessfully Created the Enity. <br/> Must include a response body. |
14+
|201 (Created) | Sucessfully Created the Enity. <br/> Must include a response body. |
1615
|202 (Accepted) | Actions that take a long while to process/ Batch/Queue Oriented Process |
1716
|204 (No Content) | When the REST API declines to send back any status message or representation in the response message’s body. Must not contains the response body|
1817
|401 (Unauthorized) | Invalid Credentials/ Invalid Authentication |
1918
|403 (Forbidden) | Invalid Authorization/ Insufficient rights/ Incorrect Role |
2019
|400 (Bad Request) | Bad request object | validation error |
21-
|405 (Method Not allowed) | If API supports methods other than GET request |
22-
|410 (Gone) | Expired link/Server no longer serve this request.|
20+
|405 (Method Not allowed) | If API supports methods other than POST request |
2321
|500 (Internal server error)| Server encountered an unexpected condition that prevented it from fulfilling the request.|

docs/rest-api/put.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,18 @@ title: Put Method
44
sidebar_label: Put
55
---
66

7-
#### The following convention should be followed for Put
7+
Use **PUT** APIs primarily to update existing resource (if the resource does not exist, then API may decide to create a new resource or not). If a new resource has been created by the PUT API, the origin server MUST inform the user agent via the HTTP response code 201 (Created) response and if an existing resource is modified, either the 200 (OK) or 204 (No Content) response codes SHOULD be sent to indicate successful completion of the request.
8+
9+
> * **/employees/{employee-id}**
10+
> * **/departments/{department-id}**
11+
12+
| Response code | Result/Reason |
13+
|---------------------------|------------------------------|
14+
|200 OK | Sucessfully updated the Enity. <br/> Must include a response body. |
15+
|204 (No Content) | When the REST API declines to send back any status message or representation in the response message’s body. Must not contains the response body|
16+
|401 (Unauthorized) | Invalid Credentials/ Invalid Authentication |
17+
|403 (Forbidden) | Invalid Authorization/ Insufficient rights/ Incorrect Role |
18+
|400 (Bad Request) | Bad request object | validation error |
19+
|404 (Not found) | If ID not found or invalid|
20+
|405 (Method Not allowed) | If API supports methods other than PUT request |
21+
|500 (Internal server error)| Server encountered an unexpected condition that prevented it from fulfilling the request.|

0 commit comments

Comments
 (0)