API Reference

Response

This document provides an overview of the API response structure used in the system

This document provides an overview of the API response structure used in the system. All responses are in JSON format and consist of a code and message field. In the case of an error, an array of errors may also be included. Additionally, appropriate HTTP status codes are utilized along with system codes to convey the outcome of the API request.

Response Structure

The API responses adhere to the following structure:

{
  "code": <system_code>,
  "message": "<message>"
}
  • code: The code field represents the system-specific code that categorizes the response outcome. It helps identify and handle different scenarios programmatically.
  • message: The message field provides a human-readable description or explanation of the response.

Error Responses

In the case of an error, the response structure expands to include an array of errors:

{
  "code": <system_code>,
  "message": "<message>",
  "errors": [
    {
      "field": "<field_name>",
      "message": "<error_message>"
    },
    {
      "field": "<field_name>",
      "message": "<error_message>"
    },
    ...
  ]
}
  • errors: The errors field is an array containing individual error objects. Each error object includes information about the specific error, such as the field where the error occurred and a corresponding message describing the error.

HTTP Status Codes

The API utilizes appropriate HTTP status codes to indicate the outcome of each request. The status codes provide additional information beyond the system-specific code mentioned above. Some commonly used status codes include:

  • 200 OK: The request was successful, and the response body contains the requested data.
  • 201 Created: The request to create a new resource was successful, and the response body contains the newly created resource.
  • 400 Bad Request: The request was invalid or malformed. The response body may provide more information about the error, including the errors array.
  • 401 Unauthorized: The client's request lacks valid authentication credentials or the provided credentials are invalid.
  • 403 Forbidden: The client is authenticated but does not have permission to access the requested resource.
  • 404 Not Found: The requested resource does not exist on the server.
  • 500 Internal Server Error: An unexpected error occurred on the server.

The combination of the HTTP status code and the code field in the response allows for precise identification and handling of various scenarios.

Conclusion

The API response structure follows a consistent format using JSON, consisting of a code and message field. In case of an error, an array of errors is included. The API also utilizes appropriate HTTP status codes to indicate the outcome of each request. By understanding the response structure and leveraging the provided information, clients can effectively handle responses and troubleshoot issues when interacting with the API.