Restberry works with both Express and Restify!
Framework for setting up RESTful JSON APIs with NodeJS. Define your models and setup CRUD API calls without needing to write any code (see Usage). All API calls will handle and identify issues and throw necessary HTTP responses and easy to debug error responses. Restberry also handles authentication and permission checks and throws appropriate errors.
Install
npm install restberry
Example
See example
for a detailed documentation of how you setup a Restberry app.
Usage
var restberry = ; restberry ; restberry routes ; restberry routes ;
NOTE: By default, Restberry integrates with ExpressJS and Mongoose but it can be hooked up with other packages. See more usages in the tests and dependent packages like:
Response examples
All these responses below are automatically handled without needing to write any additional code.
- 200 OK
2014-05-11T11:55:53.916Z|172.16.122.129|GET|/api/v1/foos/536f6549e88ad2b5a71ffdc6|<{}>2014-05-11T11:55:53.920Z|172.16.122.129|200|<{ "foo": }>
- 201 CREATED
2014-05-11T11:55:54.210Z|172.16.122.129|POST|/api/v1/foos|<{ "name": "test"}>2014-05-11T11:55:54.210Z|172.16.122.129|201|<{ "foo": }>
- 204 NO CONTENT
2014-05-11T11:55:52.575Z|172.16.122.129|DELETE|/api/v1/foos/536f6548e88ad2b5a71ffdb7|<{}>2014-05-11T11:55:52.579Z|172.16.122.129|204|
NOTE: See restberry-errors
for possible error responses.
Authentication
See restberry-passport
.
Routing
restberry routes // POST /foos // DELETE /foos/:id // POST /foos/:id // GET /foos // GET /foos/:id // PUT /foos/:id // All of the above...
Handle action query strings like this:
restberry routes
And Handle parent models like this:
restberry routes // POST /bars/:id/foos
NOTE: this can only be applied to ReadMany and Create.
You can also create custom routes. The possible configurations you can make are:
restberry routes
NOTE: you can set these properties to all the predefined API definitions,
you won't be able to override action
however.
Run the tests
npm test
Further reading
I have written an article series on RESTful JSON API design which this package is base upon, you can find the three parts here: part 1, part 2 and part 3.
Contact
I'm really interested to here what you guys think of Restberry, especially if you have any suggestions to improve the package. Please contact me at thematerik@gmail.com.