Warning: currently only works with ember-cli master until it's version is > 0.0.37
This Ember CLI addon provies a rest-api
blueprint that is compatible with the Ember Data DS.RESTAdapter.
It creates express routes in 'server/routes/' that are then automatically served through the ember serve
command.
npm install ember-cli-rest-api-blueprint --save-dev
The generated REST API depends on
- nedb: a very simple database
- ember-inflector-node-shim: a shim to use ember-inflector (to pluralize the modelname)
Thus, you need to add these dependencies to your project with:
npm install nedb --save-dev
npm install git://github.com/manuelmitasch/ember-inflector-node-shim --save-dev
To create a REST API for a model called post
type:
ember generate rest-api post
The REST API is namespaced with /api
to avoid route collisions with the routes defined in your Ember app. Thus, it can be accessed through:
0.0.0.0:4200/api/posts
By default the generated REST route uses nedb as a in-memory store. Thus, all changes are lost after you restart the server.
To persist the data you can specify a filename when creating the db
object:
db = new Datastore({ filename: 'path/to/datafile', autoload: true });
[] Add a post-install script that adds the dependencies to the ember app.