JSON API - A specification for building APIs in JSON
Is there any standard for JSON API response format? - Stack Overflow
A simple JSON API spec
Should I adhere to the JSON::API specification when developing APIs? Jbuilder or jsonapi-serializer?
Videos
Yes there are a couple of standards (albeit some liberties on the definition of standard) that have emerged:
- JSON API - JSON API covers creating and updating resources as well, not just responses.
- JSend - Simple and probably what you are already doing.
- OData JSON Protocol - Very complicated.
- HAL - Like OData but aiming to be HATEOAS like.
There are also JSON API description formats:
- Swagger
- JSON Schema (used by swagger but you could use it stand alone)
- WADL in JSON
- RAML
- HAL because HATEOAS in theory is self describing.
Google JSON guide
Success response return data
{
"data": {
"id": 1001,
"name": "Wing"
}
}
Error response return error
{
"error": {
"code": 404,
"message": "ID not found"
}
}
and if your client is JS, you can use if ("error" in response) {} to check if there is an error.
Hello everyone!
I'm currently working on a Rails project and am considering using either Jbuilder or jsonapi-serializer for handling JSON responses. I'm aware that the JSONAPI specification provides a standardized approach for APIs, but I'm undecided on whether to adhere to it.
For my project, I'm not heavily focused on documentation but rather on a code-first approach. I'd love to hear your thoughts:
Would you still recommend following the JSONAPI specification even if documentation isn't a priority?
For a Rails project, do you prefer Jbuilder or JSONAPI-Serializer? Why?
Looking forward to your insights and experiences.