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
5
votes
1 answer

An EmberJS DataStore adapter which supports HATEOAS

I'm creating an app which I'd really like to be quite RESTful that follows the HATEOAS REST requirement. On the front-end, I'm looking at using Ember because it seems pretty much in line with how I like to build front-end apps. Unfortunately though,…
basicallydan
  • 1,984
  • 3
  • 24
  • 39
4
votes
1 answer

How to validate JSON payload against OpenApi specification from Ruby?

I have HTTP request payload structured according to jsonapi.org guidelines: { "data": { "type": "employee", "attributes": { "firstName": "John", "lastName": "Doe", } } } then I have OpenApi specification (yaml) of this…
Peter
  • 1,549
  • 2
  • 16
  • 24
4
votes
1 answer

HATEOAS and forms driven by the API

I'm trying to apply HATEOAS to the existing application and I'm having trouble with modeling a form inputs that would be driven by the API response. The app is allowing to search & book connections between two places. First endpoint allows for…
4
votes
1 answer

How to handle removing a relationship in JSON:API?

We are currently developing a single page application using Ember and CakePHP. We use JSON:API format for transmitting data. However, when creating a relationship the client transmits the id. When removing the relationship Ember transmits the id as…
4
votes
2 answers

Consuming HATEOAS API from native clients, Is REST really REST?

I'm writing Web API in ASP NET Core and I want to consume it from single page applications (e.g. using Angular, Vue, React), native desktop applications and mobile applications. I stumbled across concept called "HATEOAS" and I learnt that the API…
Konrad
  • 4,264
  • 8
  • 33
  • 71
4
votes
1 answer

Chai to test JSON API output

How can I use Chai to deep parse JSON API output? JSON API Output: { "data": { "id": "87zc08spyq69", "type": "data-collector", "attributes": { "sensors": [ { "metadata": { …
Roobie
  • 1,136
  • 4
  • 11
  • 21
4
votes
2 answers

Handling an error with multiple attributes or parameters with JSON API

JSON API specifies that multiple errors on an attribute/parameter should be listed separately. What is the best way to handle a single error that involves several parameters at once? For example, let's say an endpoint accepts either bid or fold…
Arman H
  • 5,018
  • 9
  • 47
  • 70
4
votes
3 answers

Rails Active Model Serializer include in controller not injecting has many relationship in included parameter

I'm seeing a strange behaviour regarding rails 5, active model serializer and the json-api adapter. Given the following User model with the Rolify gem: class User < ActiveRecord::Base # # Gem Includes # rolify # Include devise modules. …
4
votes
1 answer

Json Api Resources | response with array of objects

I am using the json api resource gem in my project. I have setup a simple resource module V1 class ExpectedPaymentResource < JSONAPI::Resource attributes :registration_id, :invoiced_amount_due, :date_due, :status, :created_at, :updated_at …
David North
  • 357
  • 1
  • 2
  • 15
4
votes
2 answers

Should JSON Api attributes element contain nested objects?

This is the first time we are using JSON API in our projects and according to specification on their web, this is what a regular JSON API response should look like HTTP/1.1 200 OK Content-Type: application/vnd.api+json { "data": [{ "type":…
mko
  • 4,825
  • 8
  • 45
  • 97
4
votes
2 answers

dotnet core webapi json-api compliant querystring route

I'm trying to grab the "status" and "all" key, value from the requested URL, and can't figure out how to build my class object. The JSON API specification I'm referring to can be found here: http://jsonapi.org/recommendations/#filtering // requested…
Carl Sagan
  • 940
  • 11
  • 29
4
votes
2 answers

Conflict in type inflection between EmberData and Django REST framework

EmberData is POSTing: { "data": { "attributes": { "name": "The project name", "description": "The project description", "price": 123 }, "relationships": { "onwer": { "data": null } }, …
blueFast
  • 33,335
  • 48
  • 165
  • 292
4
votes
3 answers

Context is always nil using jsonapi-resources

Using version 0.6.0 of the jsonapi-resources gem in conjuction with Doorkeeper I am having a problem seeing the current user in the context object in my resource. I am basically following the docs, however nothing I try will make the context I set…
Dhaulagiri
  • 3,291
  • 22
  • 26
4
votes
1 answer

How to use json-api pagination links in Ember 2.x?

Currently I'm working on app using Rails (4.1.0) API and Ember (2.1.0) and I'm having hard time making pagination in Ember side works. Rails API JSON output includes automatically made pagination links (from combination of JSON API adapter in AMS…
4
votes
2 answers

java object from json (json-api)

I want to convert a JSON object written with json-api conventions into a Java object. I thought about using the katharsis library, but I couldn't see if it could be used for this purpose. Does anyone have any idea how could I achieve this?
pixie
  • 457
  • 8
  • 20