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

sails101/using-the-jsonapi-format

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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 = format;

Final Step

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

Use Cases

For frontend frameworks like Ember.js that are 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