API Design Guidelines #24
Replies: 2 comments 3 replies
-
Thanks for putting this proposal together Caleb. This is an excellent place to start. I've included my suggestions and questions inline below.
I think it'd be helpful to provide a quick example here similar to how you listed the CRUD operations above. Also linking out to the spec is a helpful addition: https://jsonapi.org/format/#document-resource-identifier-objects
Do we just want to say, use HTTPS all the time, and any URL that requests only HTTP should automatically be redirected to the HTTPS version?
I suggest including this link: https://jsonapi.org/format/#fetching-filtering
I suggest including this link: https://jsonapi.org/format/#fetching-pagination
I'm guessing that data would be the
I don't see
And Meta:
Errors:
I suggest including this link: https://jsonapi.org/format/#fetching-resources-responses
I suggest including this link for CREATE of a new resource: https://jsonapi.org/format/#crud-creating-responses
It'd be good to include a CREATE, UPDATE and DELETE example here too
|
Beta Was this translation helpful? Give feedback.
-
@jhodapp Thank you for excellent the feedback on this! I made some updates to the guidelines based on your suggestions. In particular, I modified the first guideline to:
as a sort of fallback disclaimer so that we do not need to reiterate the entire spec in our guidelines here. Let me know if that seems adequate to you. Trying to account the inevitable things that will fall through the cracks. This way we'll have something to refer to in those situations. |
Beta Was this translation helpful? Give feedback.
-
Proposal For Adopting a Set of Standardized API Guidelines
Goal:
To define a set of standard conventions that we agree to adhere to in order to build an ergonomic, functional, cohesive API.
Proposed Guidlines
General Design Principles
Utilize JSON API specification for consistent data formatting and structure in cases not covered by these guidelines.
Employ standard HTTP methods for CRUD operations (
GET
,POST
,PUT
,DELETE
).Name resources with singular nouns and collections with plural nouns (
/User
for a single user,/Users
for a collection ).Implement resource identification using unique identifiers (UUID).
Always use HTTPS. Any attempts to use HTTP should automatically be redirected to HTTPS counterpart.
Filtering
Allow filtering resources by specifying criteria in the query string.
Support common filter operators like
eq
,ne
,gt
,lt
,gte
,lte
,in
, andnin
.Enable filtering multiple attributes using a comma-separated list.
Use JSON API syntax for filter parameters (e.g.,
?filter[name]=John
).Pagination
Implement pagination for large datasets to optimize performance.
Provide pagination parameters
page[number]
andpage[size]
in the query string.Include pagination information in the response header (e.g., Link) and meta field.
Implement cursor-based pagination for efficient handling of large datasets and updates.
JSON API Response Format
Utilize JSON API format for response structure, including:
data
: An object representing the requested resource or collection.meta
: Additional information about the response.errors
: An array of error objects if the request fails.Utilize standard HTTP status codes to communicate the outcome of the request. Here are some of the most common codes and their appropriate usage:
200
OK: The request was successful and the requested resource is available in the response.201
Created: The request successfully created a new resource.202
Accepted: The request has been accepted for processing, but the processing has not yet been completed.204
No Content: The request was successful, but there is no content to return in the response.301
Moved Permanently: The requested resource has been permanently moved to a new location.302
Found: The requested resource has been temporarily moved to a new location.400
Bad Request: The request is malformed or contains invalid syntax.401
Unauthorized: The request requires authentication and the user is not authorized.403
Forbidden: The user is authorized but does not have permission to access the requested resource.404
Not Found: The requested resource could not be found.405
Method Not Allowed: The requested method is not supported for the requested resource.422
Unprocessable Entity: The request was well-formed but the server could not process it due to semantic errors.500
Internal Server Error: An unexpected error occurred on the server.503
Service Unavailable: The server is currently unavailable.Generic Examples:
Request (GET with filtering):
GET /api/v1/users?filter[name]=John&filter[age][gt]=18
Response (successful):
Request (GET with pagination):
GET /api/v1/users?page[number]=2&page[size]=5
Response (successful):
Request (GET with error):
GET /api/v1/users?filter[invalid_attribute]=invalid_value
Response (error):
Resources:
Beta Was this translation helpful? Give feedback.
All reactions