I am currently writing some micro services with Foxx to be consumed by Ember.js. Ember data plays very nicely with JSON API (http://jsonapi.org) responses. So I tried to serialize the Foxx responses with the json-api-serializer (https://www.npmjs.com/package/json-api-serializer) - but with no luck. I only found the forClient method, but this only allows me to operate on the JSON representation of single objects, not the whole response. So my question: Is it possible to implement JSON API with Foxx/ArangoDB?
Asked
Active
Viewed 146 times
1 Answers
3
You can return arbitrary responses from Foxx routes, so it's entirely possible to generate JSON responses that conform to JSON API.
However there's no built-in way to do this automatically.
I don't see anything in json-api-serializer
that shouldn't work in Foxx, so I'm not sure what problems you are encountering. You should be able to simply return the output object with res.json(outputFromSerializer)
and set the content type with res.set('content-type', 'application/vnd.api+json')
.
If everything else fails you can just write your own helper functions to generate the boilerplate and metadata JSON API expects.

Alan Plum
- 10,814
- 4
- 40
- 57
-
OK, you are right. My problem was that I've fiddled around in the model's forClient method instead of implementing the serialization directly in the route. In the route it works like a charm. Thanks for pointing me in the right direction! – JPS Aug 30 '16 at 15:48