API
Architecture
- The team generally follows RESTful and JSON API. In addition, before designing a new API, review the recommended practices outlined in the Heroku API Design Guide.
- Use version endpoints e.g.
v1/
,v2/
. - Endpoints and parameters must be documented. Postman and OpenAPI (Swagger) are the preferred tools.
Formatting
-
Use String format for Float/Double attributes.
{ "amount": 123.456789 }
{ "amount": "123.456789" }
-
Use the RFC 3339 format (
yyyy-MM-dd'T'HH:mm:ss.SSSZ
) for DateTime attributes.{ "updated_at": "2023-07-13 12:02:33" }
{ "updated_at": "2023-07-13T12:02:33.123Z" }
Errors
The conventional HTTP status codes must be used to indicate the success or failure of an API request. In general:
- Codes in the
2xx
range indicate success. - Codes in the
4xx
range indicate an error that failed given the information provided (e.g., required parameters missing, invalid pin or OTP, invalid token, etc.). - Codes in the
5xx
range indicate an error with the servers.
Regardless of the HTTP status code, add an error_code
that references the occurring error to make the error payload more explicit for consumers. For example, some 4xx
errors that could be handled programmatically for different reasons (e.g., expired token or invalid login credentials) with the same HTTP status code.
Check out more about the JSON:API error objects for reference