0.0.5 • Published 10 years ago
axes-api v0.0.5
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 Apiis 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.0will be out soon! - enjoy :)
Installation
$ npm install axes-apiUsage
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, andattributeswill 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 associations3) 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
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/examplemodelExample 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=testDependencies
Version
Current version: 0.0.4
License
Apache-2.0