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.

636 questions
31
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
  • 856
  • 8
  • 17
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
18
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
  • 265
  • 2
  • 11
17
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
  • 5,800
  • 3
  • 23
  • 51
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
  • 8,948
  • 16
  • 63
  • 116
15
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,…
12
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
  • 3,489
  • 2
  • 30
  • 48
11
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,556
  • 3
  • 20
  • 50
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
  • 113,812
  • 91
  • 316
  • 418
11
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
  • 34,985
  • 56
  • 167
  • 267
10
votes
0 answers

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
  • 357
  • 1
  • 2
  • 15
9
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…
9
votes
2 answers

Authentication with JWT and JSONAPI

I am implementing REST API using the following technologies/approaches: JSONAPI JWT token I want to implement authentication endpoint, it should receive username and password in POST request in JSONAPI format and return JWT token in JSONAPI…
Sergey Potapov
  • 2,900
  • 1
  • 20
  • 37
8
votes
1 answer

Add custom serializer to Swagger in my .Net core API

I'm using the JSONAPI specifications from jsonapi.org, then I'm using the JsonApiSerializer to accomplish the JSONAPI specification, so my response and request body looks like: { "data": { "type": "articles", "id": "stringId", …
HTT
  • 83
  • 3
8
votes
4 answers

WP REST API fetch posts from post type

How can I get all the posts from a specific custom post type with WP REST API (either v1 or v2)? I'm very new to this and trying to understand how to do that. I am currently using WP REST API v2 and managed to fetch a list of all the post types with…
Jeff
  • 495
  • 1
  • 8
  • 24
1
2 3
42 43