node-api-routes
A declarative system for creating express API routes. It has a few goals:
- Make declaring routes really easy to create, read, and manage.
- Allow all the usual express helpers (middleware, parameters, etc)
- Be RESTful and create OPTIONS endpoints to help developers.
Install & Usage
npm install api-routes --save
In your express app declaration:
var Api = ;var api = '/api' /* base route */; // You can add routes right hereapi; // Or use the more organized requireAll// See below for examples on how files should be organized.api; // Setup the middlewareapp;
Examples
Checkout the examples.
An entire route file may look like this:
module { api; };
Then we can query it like so:
$ curl localhost:8000/api/testgotten$ curl localhost:8000/api/test -XPOSTposters$ curl localhost:8000/api/test -XDELETEbeleted!$ curl localhost:8000/api/test -XOPTIONS
Easy URL Sub-Paths via Inheritance
Let's imagine you want the following endpoints: /users
, /users/:id
, /users/:id/profile_pic
, users/:id/reputation
Using inheritance, you can set this up cleanly:
moduleexports = api api api api
License
MIT License found in LICENSE file.