[ADP-319] Request Body Convention
Guidelines
- MUST NOT use request body for GET method
- In browser spec, the GET request WON’T have a body(payload). See https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/send
- MAY use request body for POST, PUT, and PATCH methods
- MAY consider using request body for DELETE method when additional information is required
- SHOULD always use appropriate Content-Type header when sending a request body
Detailed Explanation
GET Method
GET requests are designed for retrieving resources without causing side effects on the server. Therefore, they should not include a request body. Instead, use query parameters for operations such as filtering, sorting, or pagination.
Example of correct usage:
http
GET /users?role=admin&status=active
Example of incorrect usage:
http
GET /users HTTP/1.1
Content-Type: application/json
{
"role": "admin"
}
POST Method
POST requests are used for creating new resources or submitting data for processing. They should include a request body containing the data to be processed or the details of the resource to be created.
Example:
http
POST /users
Content-Type: application/json
{
"username": "johndoe",
"email": "john@example.com",
"role": "user"
}