Questions tagged [json-api]

"JSON API" is a standard for building APIs in JSON format. If you've ever argued with your team about the way your JSON responses should be formatted, JSON API is your anti-bikeshedding weapon.

"JSON API" is a standard for building APIs in JSON format. If you've ever argued with your team about the way your JSON responses should be formatted, JSON API is your anti-bikeshedding weapon.

Furthermore, clients built around JSON API are able to take advantage of its features around efficiently caching responses, sometimes eliminating network requests entirely.

By following shared conventions, you can increase productivity, take advantage of generalized tooling, and focus on what matters: your application.

Here's what JSON API (in the ID style) looks like:

{
  "posts": [{
    "id": "1",
    "title": "Rails is Omakase",
    "links": {
      "author": "9",
      "comments": [ "5", "12", "17", "20" ]
    }
  }]
}

and in the URL style:

{
  "posts": [{
    "id": "1",
    "title": "Rails is Omakase",
    "links": {
      "author": "http://example.com/people/9",
      "comments": "http://example.com/comments/5,12,17,20"
    }
  }]
}

JSON API covers creating and updating resources as well, not just responses.

More information can be found on the project's homepage.

693 questions
42
votes
1 answer

What is the difference between OData, JsonAPI, GraphQL?

I have used OData in my career quite a bit and now few of my colleagues from different teams recommended we move to JsonAPI and GraphQL as its not tied to Microsoft. I don't have much experience in both these query languages. As far as i know OData…
Navap
  • 1,050
  • 9
  • 18
26
votes
3 answers

What is the suitable HTTP status code when request is successful but has warning messages?

In proper usage of REST, what is suitable the HTTP status code when request is successful but has warning messages? In our case; clients are web applications running on browsers. We prefer status codes as following: HTTP 200, 201, 204 when request…
ykaragol
  • 6,139
  • 3
  • 29
  • 56
26
votes
4 answers

Jackson deserialize single item into list

I'm trying to consume a service that gives me an entity with a field that it's an array. { "id": "23233", "items": [ { "name": "item 1" }, { "name": "item 2" } ] } But when the array contains a single item, the…
Javier Alvarez
  • 1,409
  • 2
  • 15
  • 33
23
votes
1 answer

Handling errors with the (now default) Ember Data JSON-API adapter

I am using Ember 1.13.7 and Ember Data 1.13.8, which by default use the JSON-API standard to format the payloads sent to and received from the API. I would like to use Ember Data's built-in error handling in order to display red "error" form fields…
danr1979
  • 461
  • 1
  • 3
  • 10
19
votes
1 answer

How to create compound documents?

I'm thinking of using the JSONAPI standard for the design of our API. One thing this API must be able to do, is accept a compound document (several layers deep) and create it. The root object owns all descendants ('to-many' relationships) which the…
Jeroen Knoef
  • 275
  • 1
  • 2
  • 11
18
votes
2 answers

OpenAPI vs JSON:API

I couldn't find any resources on the use case differences between JSON:API & OpenAPI From my understanding, JSON:API is more focused on the business data while OpenAPI is more about REST itself? Any pointers would be great, thanks!
Webber
  • 941
  • 11
  • 26
16
votes
4 answers

Serialize an array of models using active_model_serializers

I am trying to send the serialized version of a model to a view as a param, using the gem active_model_serializers #app/serializers/admin_serializer.rb class AdminSerializer < ActiveModel::Serializer attributes :id, :email,…
16
votes
2 answers

How to create a child entity in to-many relationship with JSONAPI

I've been reading through jsonapi's docs and I can't wrap my head around how this is practical. According to the docs to add a comment to an article the comment must already exist. POST /articles/1/relationships/comments HTTP/1.1 Content-Type:…
David
  • 10,418
  • 17
  • 72
  • 122
14
votes
1 answer

Specifying sort order in a JSON API

My team recently adopted the json api convention. In the documentation for the api sorting is not addressed. They do however address filtering in the recommendations page but in my opinion, sorting is not part of filtering since filtering is used…
dipole_moment
  • 5,266
  • 4
  • 39
  • 55
13
votes
1 answer

Sending json api object using postman

I am using JSONAPI Specification http://jsonapi.org/format/#status And I have data like below, { "data": { "type": "tag", "id": "1", "attributes": { "name": "Test" } } } How do I make a post request to the end point…
Mauricio Junior
  • 135
  • 1
  • 2
  • 5
13
votes
6 answers

How do I get the Wordpress JSON-API to work on Nginx server?

For some reason "out-of-the-box" the Wordpress JSON API does not work on Nginx. I have tried several redirect schemes in the nginx conf. The only thing I have gotten to work is ?json. However, this does not work for authentication and…
etrey
  • 447
  • 3
  • 6
  • 15
12
votes
2 answers

Ember: Relationship link related data not loading / disappearing

I'm experiencing somewhat of a bug with Ember/Ember-data. Here's my scenario: Client lands on / route and Ember loads data from /api/v1/videos?limit=8. The response comes from a rails-api backend using active_model_serializers which ensures the…
Maros
  • 1,825
  • 4
  • 25
  • 56
12
votes
1 answer

JSON API filtering standards for more complex queries

I am writing a REST api using ruby on rails. I am using json api as a guide for the standards to use when building the api. I am trying to figure out the best way to use filtering in the GET requests. The json api recommendations for filtering only…
David North
  • 437
  • 1
  • 4
  • 17
12
votes
2 answers

JSONAPI - Difference between self and related in a links resource

Why is the self and related references different in the below JSONAPI resource? Aren't they pointing to the same resource? What is the difference between going to /articles/1/relationships/tags and /articles/1/tags? { "links": { "self":…
jax
  • 37,735
  • 57
  • 182
  • 278
11
votes
2 answers

Should nested relationships be reflected in URLs for JSON API?

I'm trying to follow JSON API. I need to expose CRUD access to a nested resource: product reviews. Prior to using JSON API, I'd expect a REST interface like this: GET /products/:product_id/reviews - list reviews for a product POST …
Nathan Long
  • 122,748
  • 97
  • 336
  • 451
1
2 3
46 47