Skip to content

Commit 806588d

Browse files
REST API GET and POST Request contents added.
1 parent cf114db commit 806588d

File tree

5 files changed

+57
-15
lines changed

5 files changed

+57
-15
lines changed

docs/rest-api/get.md

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

7-
#### The following convention should be followed for Get
7+
Use **GET requests** to retrieve resource representation/information only – and not to modify it in any way. As GET requests do not change the state of the resource, these are said to be safe methods. Additionally, GET APIs should be **idempotent**, which means that making multiple identical requests must produce the same result every time until another API (POST/PUT/PATCH/DELETE) has changed the state of the resource on the server.
8+
9+
> * **/employees**
10+
> * **/employees/{employee-id}/leaves**
11+
> * **/employees/{employee-id}/employee-reports**
12+
13+
| Response code | Result/Reason |
14+
|---------------------------|------------------------------|
15+
|200 OK | Sucessfully Fetched the Enity. <br/> Must include a response body. |
16+
|404 (Not found) | If Entity not found for given ID or is invalid ID|
17+
|405 (Method Not allowed) | If API supports methods other than GET request |
18+
|401 (Unauthorized) | Invalid Credentials/ Invalid Authentication |
19+
|403 (Forbidden) | Invalid Authorization/ Insufficient rights/ Incorrect Role |
20+
|410 (Gone) | Expired link/Server no longer serve this request.|
21+
|500 (Internal server error)| Server encountered an unexpected condition that prevented it from fulfilling the request. |

docs/rest-api/naming-convention.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
id: naming-convention
3+
title: Naming Convention
4+
sidebar_label: Naming Convention
5+
---
6+
7+
In REST(**REpresentational State Transfer**), primary data **representation** is called **Resource**. Having a strong and consistent REST resource naming strategy – will definitely prove one of the best design decisions in the long term.
8+
9+
* Use **noun** and **hyphenated-lower-case** for CRUD operations to an entity/resource/document. The **GET/POST/PUT/DELETE/PATCH** requests represents the corresponding CRUD operation for the following resources like employees, reports, leaves.
10+
11+
> * **/employees**
12+
> * **/employees/{employee-id}/leaves**
13+
> * **/employees/{employee-id}/employee-reports**
14+
15+
* For cases of executable functions besides a basic CRUD operations, use **verb** and **hyphenated-lower-case**.
16+
17+
> * **/customer/{customer-id}/check-validity**
18+
> * **/customer/{customer-id}/cart/checkout**

docs/rest-api/post.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,20 @@ title: Post Method
44
sidebar_label: Post
55
---
66

7-
#### The following convention should be followed for Post
7+
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).
8+
9+
> * **/employees**
10+
> * **/employees/{employee-id}/leaves**
11+
> * **/employees/{employee-id}/employee-reports**
12+
13+
| Response code | Result/Reason |
14+
|---------------------------|------------------------------|
15+
|201 OK | Sucessfully Created the Enity. <br/> Must include a response body. |
16+
|202 (Accepted) | Actions that take a long while to process/ Batch/Queue Oriented Process |
17+
|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|
18+
|401 (Unauthorized) | Invalid Credentials/ Invalid Authentication |
19+
|403 (Forbidden) | Invalid Authorization/ Insufficient rights/ Incorrect Role |
20+
|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.|
23+
|500 (Internal server error)| Server encountered an unexpected condition that prevented it from fulfilling the request.|

docs/rest-api/security.md

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,14 @@ sidebar_label: Security
66

77
## Best Practices to Secure REST APIs
88

9-
### Always Use HTTPS
9+
* Always Use HTTPS.If you use HTTP 2, to improve performance – you can even send multiple requests over a single connection, that way you avoid the complete TCP and SSL handshake overhead on later requests.
1010

11-
* By always using SSL, the authentication credentials can be simplified to a randomly generated access token that is delivered in the username field of HTTP Basic Auth. It’s relatively simple to use, and you get a lot of security features for free.
12-
13-
* If you use HTTP 2, to improve performance – you can even send multiple requests over a single connection, that way you avoid the complete TCP and SSL handshake overhead on later requests.
11+
* Never expose information on URLs. <https://api.app.com/users/{id}/fetch?apiKey=abcd123456789> //Bad practice
1412

15-
### Never expose information on URLs
13+
* Conside using token based authentication like OAUTH2
1614

17-
* Usernames, passwords, session tokens, and API keys should not appear in the URL, as this can be captured in web server logs, which makes them easily exploitable. e.g
18-
https://api.app.com/users/{id}/fetch?apiKey=abcd123456789 //Bad practice
15+
* Consider Adding Timestamp in Request
1916

20-
### Conside using token based authentication like OAUTH2
17+
* Log each request and response data
2118

22-
### Consider Adding Timestamp in Request
23-
24-
### Log each request and response data
25-
26-
### Validate Incoming request
19+
* Validate and sanitize incoming requests against data types, injections

sidebars.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module.exports =
1010
"type": "category",
1111
"label": "Methods",
1212
"items": [
13+
"rest-api/naming-convention",
1314
"rest-api/get",
1415
"rest-api/post",
1516
"rest-api/put",

0 commit comments

Comments
 (0)