spring-hateoas icon indicating copy to clipboard operation
spring-hateoas copied to clipboard

Provide JSON API support

Open sdeleuze opened this issue 11 years ago • 35 comments

I create this feature request after some discussions and thoughts that happen after the JSON API in a Java Web Application blog post and on the SPR-13570.

JSON API is a specification for how a client should request that resources be fetched or modified, and how a server should respond to those requests. Clients built around JSON API are able to take advantage of its features around efficiently caching responses, sometimes eliminating network requests entirely. Why not use the HAL specification? is also worth to read.

Ultimately, the goal of this feature is to provide support for the client-side Javascript JSON API libraries, like the most advanced one Ember Data.

I am not a Spring HATEOAS expert, but my thoughts about that is that such support may be achieved by adding JSON API format support in addition to HAL, and providing standardized ResourceController/RelationshipController Spring MVC controller interfaces that may the the Spring couterpart of Katharsis ResourceRepository/RelationshipRepository. This last point seems quite important since JSON API is not just a format, and also defines standardized REST endpoints for dealing with CRUD and relationship operation. You can have a look to RESThub RestController for an example of such controller interface.

I have not the knowledge to contribute that support alone, but I will be happy to contribute.

sdeleuze avatar Oct 18 '15 11:10 sdeleuze

I am all in for being able to produce JSON API compliant output for ResourceSupport subtypes. However, it feels like the spec suffers quite a bit from feature creep (see the aforementioned Fetching) which makes implementing only the hypermedia aspects quite tricky.

I guess we can start simple and take it from there.

odrotbohm avatar Oct 18 '15 11:10 odrotbohm

Just to mention @sdeleuze currently most advanced JS client is Orbit.js that has adapter for ember-data. It is maintained by the guys behind JSON API.

masterspambot avatar Oct 18 '15 16:10 masterspambot

@masterspambot Thanks for noticing, I was not aware of this one. It seems very interesting (and not specific to EmberJS).

sdeleuze avatar Oct 18 '15 16:10 sdeleuze

:+1: for JSON API support

keithdmoore avatar Feb 09 '16 21:02 keithdmoore

When we can expect the first release?

dom-atom avatar Feb 10 '16 12:02 dom-atom

@dom-atom @keithdmoore Katharsis we already have Spring Adapter supporting fully JSON API 1.0 standard: https://github.com/katharsis-project/

masterspambot avatar Feb 10 '16 14:02 masterspambot

:+1:

amaltson avatar Feb 12 '16 00:02 amaltson

Is Katharsis a valid way to support JSON-API in Spring (boot)? I ask because they don't actually provide a controller and endpoints. They provide a filter that magically maps things to your model. It does appear to work, but it feels odd to not have actually endpoints. Additionally I have found an SO post that indicates it doesn't play nice with Spring Security.

Is there a way to use JSON-API with Spring-HATEOS instead of HAL? That may be more of what I am looking for...

Currently, Ember Data supports JSON-API natively and we are using Ember...

donahchoo avatar Apr 06 '17 06:04 donahchoo

There are actually several efforts in progress (I know it's been slow) to add some more mediatypes including Collection+JSON, Siren and Uber. I briefly looked at JSON API back when this issue was raised.

I'm quite aware of the popularity of JSON API in the Ember community. After we go through these other mediatypes, I feel we will have learned enough to make a better decision on JSON API and how to approach that as well.

gregturn avatar Apr 06 '17 06:04 gregturn

@donahchoo - I can answer your question about Katharsis but it's off topic here. Create and issue there or find me in the gitter room for katharsis.

chb0github avatar Apr 06 '17 06:04 chb0github

I am looking forward to it.

slinjhu avatar May 10 '17 21:05 slinjhu

I'm also using Ember (Data) and it's expecting that the response is fully-compliant JSON API as per the error I'm getting: ember-metal.js:3987 Error: Assertion Failed: normalizeResponse must return a valid JSON API document: * One or more of the following keys must be present: "data", "errors", "meta".

Are there any news on the progress of things mentioned here?

javac9 avatar Nov 05 '17 09:11 javac9

Is there work done in this that can be shared? I would be interested to know the status.

marceloverdijk avatar Jan 09 '18 10:01 marceloverdijk

I poked at the spec a couple years ago and found it hard to discern where links should go. I haven't made any more progress on this mediantype.

I'm presently working on unifying my Collection JSON efforts from two years ago with our newly released Affordances API. After that it may be possible to revisit JSON API, though I'll probably push through Uber first since the work is mostly done.

gregturn avatar Jan 09 '18 12:01 gregturn

No worries, was just wondering. After evaluating various hypermedia specifications. I liked the clear flattened includes approach of jsonapi to "cache"/include linked resources.

marceloverdijk avatar Jan 09 '18 12:01 marceloverdijk

But that said there are not many implementations for jsonapi resources in Java. Both http://katharsis.io/ and http://www.crnk.io/ look very similar (forked?). Both requireda to implement a ResourceRepositoryV2 repository which feels a bit weird. I was hoping there was some vanilla Java library for jsonapi just like there is https://github.com/otto-de/edison-hal for HAL.

marceloverdijk avatar Jan 09 '18 12:01 marceloverdijk

@maciejwalkowiak While not exactly what you want, we have no issues using jsonapi-converter in our controllers to convert standard ResponseEntities (Of type String) into Json API Spec which Ember is happy with.

I have a very generic common library here which may or may not help.

peavers avatar Jan 15 '18 23:01 peavers

@peavers thx for mentioning jsonapi-converter; it look interesting 👍

marceloverdijk avatar Jan 16 '18 07:01 marceloverdijk

Are there any plans to revisit this in the near future? Thanks.

vpavic avatar Oct 25 '18 12:10 vpavic

I haven't re-read the spec since last. I just remember it being awkward that links had two different places to go. Hence, I had to guess that perhaps one was for IANA-standard rels, and the other for custom user rels.

So we could revisit it if there appears to be enough community interest.

The real question is, since this mediatype appears heavily favored by the Ember.js community is, if we supported it would Spring HATEOAS becomes a more popular means for server side Ember apps, or would the community in general stick with nodeJS?

gregturn avatar Oct 25 '18 21:10 gregturn