Package Exports
- sails-json-api-blueprints
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (sails-json-api-blueprints) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Sails-JSON-API-Blueprints
Sails hook to automatically turn a Sails.js API into a JSON API compatible interface.
This hook is still in intense development. See the Roadmap section for more information on what is yet to be implemented
While this module will provide your API with a generic implementation of JSON API, it was primarily intented to ease the communication between Sails.js and Ember.js. Ember works by default with JSON API. Here is a demonstration of sails-json-api-blueprints working with an Ember application : https://github.com/dynamiccast/sails-ember-super-rentals-example
Install
Being a sails hook. There is not much thing to do to make your sails app JSON API compatible. all you have to do is install this node module.
npm install --save sails-json-api-blueprintsPlease note the following :
- Being a set of blueprints this only works if
sails.config.blueprints.restis set to true (is it by default) sails.config.blueprints.pluralizewill be set to true to match the JSON API specification
Usage
With the hook being installed, all your auto generated controller actions will be JSON API compliant.
This module also injects a service available as JsonApiService in your controllers to help you deal with JSON API.
Serialize data
As shown in tests/dummy/api/controllers/UserController.js:14, JsonApiService.serialize allows to serialize any waterline data into a JSON API compliant format. Just call :
JsonApiService(modelName, DataObject);Call blueprints from custom action
As shown in tests/dummy/api/controllers/UserController.js:24, JsonApiService proxies blueprints to be accessible from any controller. Simply call the following with req and res as parameter:
findRecordsGET /{model}findOneRecordGET /{model}/{id}createRecordPOST /{model}destroyOneRecordDELETE /{model}updateOneRecordPATCH /{model}/{id}
Roadmap
- JSON API implementation
- GET all resources
- POST resource
- DELETE resource
- PATCH resource
- Return proper error if any
- Relationships
- Compound Document
- Links
- Fields
- Sorting
- Pagination
- Filtering
- Sails integration
- Allow the use of auto CreatedAt and UpdatedAt (see #3)
- Pubsub integration
- Provide a service to serialize as JSON API for custom endpoints
- Repository
- Add tests on travis
- Provide status on the build on Github
Tests
Simply run npm test
Tests expect the database to be empty. Local disk is used in the dummy app and can be deleted with rm tests/dummy/.tmp/localDiskDb.db.
Thanks
This work is greatly inspired from https://github.com/mphasize/sails-generate-ember-blueprints @mphasize did no longer actively maintain this repositiory, so I decided to fork it and to focus on JSON API compatibility.