Skip to content

How do I use the jsonapi.org format in my sails.js application?

License

Notifications You must be signed in to change notification settings

longdice/using-the-jsonapi-format

Repository files navigation

jsonapi.org standards

This allows sails to handle requests and responses via the jsonapi.org specs. For example:

{
 user: [{
 	id: 1,
 	name: 'Brian Jemilo II'
 },
 {
 	id: 2,
 	name: 'Mike R McNeil'
 }]
}

Handling Request

In the policy jsonapi.js If you are in need to have the resource property to be plural,

Wrap req.body[req.options.model] in a variable and append + 's'

resource = req.body[req.options.model] + 's';

Then replace req.body[req.options.model] with resource

Sending Responses

In the responses ok.js Format Responses to Jsonapi.org spec standards.

var format = {};
format[req.options.model] = data;
data = {};
data = format;

Final Step

Add '*': 'jsonapi' to config/policies this way it will apply to every controller.

Use Cases

For frontend frameworks like Ember.js that heavily and unforgivingly opinionated.

Author

Brian Jemilo II

Twitter - @jemiloii
Google - +jemiloii

About

How do I use the jsonapi.org format in my sails.js application?

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 65.1%
  • HTML 34.5%
  • CSS 0.4%