Creating APIs can't be easier.
apier (all lowercase) is a framework that allows the super easy creation of APIs.
It is opinionated based on my experiences with APIs the last 3 years and the structure is inspired by the Foursquare API.
I created a demo app in the apier-demo repo. Follow the instructions there to setup it up on your own, or just browse the code.
- Easy Setup
- Uses standard Node.js style urls
- Uses Mongoose Schemas
- Easily support multiple HTTP methods
- endpoint access based on user roles and public services
- Supports middlewares
- Build-in validation system
The setup and initial configuration is super easy.
var http = ;var apier = ;// create and configure an apier appvar app =;// require the endpoint filesapp;// start the serverhttp;
To configure the apier, you just need to provide the mongoDB url, the access configuration (as explained here) and define if you want apier to automatically handle database errors you want to do it yourself
The Express.js router is used internally, and so apier supports all the url formats you are used to
apier uses Mongoose to interact with the database. In the future, those will be inside the apier, but right now, you have to create your Mongoose Schemas based on the example found here, which is not that different from the usual mongoose schemas you know, you just have to copy paste the methods found below tha actual schema, and replace 'user' with your schema name.
Also, note the permissions static, that identifies which user roles can see each schema attribute. Permissions explained here
The following is an example of how we create an API endpoint (a service).
In that example we setup the update service of a user with the specified id (1234)
e.g. service url: 'http://localhost:2000/users/1234/update'
We accept both GET and POST requests.
Only logged in users that are identified with user role 'member' (admin can see anything) can access that service. Don't confuse this with the schema attributes, it's the same logic though.
We will use the validate middleware (explained below) or any other middleware.
And finally assign a callback. We pass 'this' as well to use it to send back data.
The validations system is better explained here. So, go check it out, but you can decide not to use it, since it's just a middleware, add your own :)
- Make the schemas easier to create by doing most of the heavy lifting inside apier.
npm installnpm test