Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any standard for JSON API response format?

Tags:

json

Do standards or best practices exist for structuring JSON responses from an API? Obviously, every application's data is different, so that much I'm not concerned with, but rather the "response boilerplate", if you will. An example of what I mean:

Successful request:

{   "success": true,   "payload": {     /* Application-specific data would go here. */   } } 

Failed request:

{   "success": false,   "payload": {     /* Application-specific data would go here. */   },   "error": {     "code": 123,     "message": "An error occurred!"   } } 
like image 476
FtDRbwLXw6 Avatar asked Oct 09 '12 18:10

FtDRbwLXw6


People also ask

What format is an API response?

The API provides resource data in JSON (. json), XML (. xml) or CSV (.

Is JSON:API a standard?

JSON:API sets a standard for communication; it expresses how requests to the server should be formatted, and then what the response to the client should be formatted as. Its goal is to optimize HTTP requests by reducing the number of requests needed as well as reducing the size of the packages themselves.

What is JSON format response?

JSON, or JavaScript Object Notation, is a simple machine-readable data-interchange format, which makes constructing API applications in JavaScript easy (though it can be used from other languages too!).

What is JSON:API format?

What Is JSON API (JSONAPI.org)? JSON API is a format that works with HTTP. It delineates how clients should request or edit data from a server, and how the server should respond to said requests. A main goal of the specification (now at a stable v1.


1 Answers

Yes there are a couple of standards (albeit some liberties on the definition of standard) that have emerged:

  1. JSON API - JSON API covers creating and updating resources as well, not just responses.
  2. JSend - Simple and probably what you are already doing.
  3. OData JSON Protocol - Very complicated.
  4. 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.
like image 79
Adam Gent Avatar answered Sep 28 '22 03:09

Adam Gent