axes-api
v0.0.5
Published
Axes Api maps your Sequelize models to urls to be accessed for your ExpressJS app.
Downloads
2
Maintainers
Readme
Axes Api
KevinLeighCrain/Js-Axes
Axes Api
is a Api builder that maps your Sequelize
models to urls for your ExpressJS
app.
Notes (please read)
Axes Api
is brand new and soon will have tons upcoming upgrades. (suprises awaits all :P)- the current version is so you have a feel of how you define and get started with
Axes-Api
- version
1.0.0
will be out soon! - enjoy :)
Installation
$ npm install axes-api
Usage
1) Include Axes Api
module to your source
var axes = require('axes-api')
2) Define your Sequelize
models to be mapped to url
The recommended way
// define models to be mapped from require
var models = require("../models"); // an example require
axes.define(models);
or
// define a single model to be mapped
axes.define(ExampleModel) // example url http://localhost:3000/examplemodel (will return all ExampleModel);
or
// define multiple models to be mapped
axes.define(ExampleModel, SecondExampleModel);
or
Warning: by default all your Sequelize model
associations
, andattributes
will be mapped and providing any predefined config will override existing
// define model to be mapped with custom configuration
axes.define({
model: ExampleModel,
config: {
include: [SecondExampleModel], // this will override generated include that Axes-Api provides by default
attributes: ['id', 'name'] // this will override generated attributes that Axes-Api provides by default
...
}
});
// Example code above will include `SecondExampleModel` for any `ExampleModel` api call based on your `Sequelize` model associations
3) Call apply
passing in your express app instance
// will apply HTTP methods to your ExpressJS app
axes.apply(app);
Example urls Axes Api
generates for your Sequelize models:
Working with Axes-Api
generated urls
Note: Generated urls
- http://localhost:3000/examplemodel
- http://localhost:3000/secondexamplemodel/:id?/:name?
Note: Url usage (example using curl)
Example 1) Return all models
// will return all 'ExampleModel'
curl -i -H "Accept: application/json" -H "Content-Type: application/json" http://localhost:3000/examplemodel
Example 2) Return models passing in optional parameter value (optional parameters are mapped by association/field)
// will return all 'SecondExampleModel' with a 'name' equal to 'test'
curl -i -H "Accept: application/json" -H "Content-Type: application/json" http://localhost:3000/secondexamplemodel?name=test
Dependencies
Version
Current version: 0.0.4
License
Apache-2.0