Response Codes
This section outlines the standard HTTP response codes used in the API for CRUD operations (Create, Read, Update, Delete). These codes are part of the RESTful principles for representing the status of API requests.
Common Response Codes
-
200 OK: The request was successful. This status is typically used for Read (GET) and Update (PUT) operations when the request completes successfully.
-
201 Created: The resource has been successfully created. This status is used for Create (POST) operations when a new resource is created.
-
204 No Content: The request was successful, but there is no content to return. This is often used for Delete operations.
-
400 Bad Request: The request could not be understood by the server due to malformed syntax or invalid parameters.
-
401 Unauthorized: The request requires user authentication, and the provided credentials are either missing or incorrect.
-
403 Forbidden: The server understands the request, but it refuses to authorize it. This typically occurs if the user does not have permission to access the resource.
-
404 Not Found: The requested resource could not be found on the server. This is returned if the user tries to access a non-existing resource.
-
405 Method Not Allowed: The HTTP method used in the request is not allowed for the requested resource. For example, a POST request on a resource that only supports GET.
-
409 Conflict: There is a conflict with the current state of the resource. For example, trying to create a resource that already exists.
-
422 Unprocessable Entity: The server understands the request, but it cannot process the contained instructions. This may happen if there is a semantic error with the provided data.
-
500 Internal Server Error: The server encountered an unexpected condition that prevented it from fulfilling the request.
-
503 Service Unavailable: The server is temporarily unable to handle the request due to maintenance or overload.
CRUD Operations and Response Codes
Create (POST)
- 201 Created: The resource was successfully created.
- 400 Bad Request: The provided data is invalid or incomplete.
Read (GET)
- 200 OK: The request was successful, and the resource data is returned.
- 404 Not Found: The requested resource does not exist.
Update (PUT)
- 200 OK: The resource was successfully updated.
- 400 Bad Request: The provided data is invalid or incomplete.
- 404 Not Found: The requested resource does not exist.
- 409 Conflict: The update could not be applied due to a conflict.
Delete (DELETE)
- 204 No Content: The resource was successfully deleted.
- 404 Not Found: The requested resource to delete does not exist.