Skip to content

About

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

Resources

Stars

1 star

Watchers

1 watching

Forks

 
 

Latest commit

 

History

29 Commits

Folders and files

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

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages