All Projects → restberry → Restberry

restberry / Restberry

Framework for setting up RESTful JSON APIs with NodeJS.

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to Restberry

Maintenance Book
”SurviveJS — Maintenance” book
Stars: ✭ 105 (-11.02%)
Mutual labels:  npm
Docusign Node Client
The Official DocuSign Node.js Client Library used to interact with the eSign REST API. Send, sign, and approve documents using this client.
Stars: ✭ 108 (-8.47%)
Mutual labels:  npm
Simple Boilerplate
A simple webpack boilerplate for your comfortable work with HTML, JS and CSS.
Stars: ✭ 116 (-1.69%)
Mutual labels:  npm
Instacam
Instant canvas video
Stars: ✭ 106 (-10.17%)
Mutual labels:  npm
Nekos Dot Life
Nekos.life wrapper.
Stars: ✭ 108 (-8.47%)
Mutual labels:  npm
Discord.js Musicbot Addon
This DOES NOT WORK any more. This repo only serves as an archive for is anyone wants to pickup my work. You may still join the discord however.
Stars: ✭ 109 (-7.63%)
Mutual labels:  npm
Qr Code With Logo
带头像(logo)的二维码(qrcode)生成工具,无jQuery依赖,自由调整大小
Stars: ✭ 104 (-11.86%)
Mutual labels:  npm
Php Sf Flex Webpack Encore Vuejs
A simple app skeleton to try to make every components work together : symfony 4 (latest stable at the date, but work with sf 3.3+ if you just change the versions in composer.json), symfony/flex, webpack-encore, vuejs 2.5.x, boostrap 4 sass
Stars: ✭ 118 (+0%)
Mutual labels:  npm
Bundle Phobia Cli
📦 Cli for the node BundlePhobia Service 😱
Stars: ✭ 108 (-8.47%)
Mutual labels:  npm
React Native In App Message
React Native in-app notification component
Stars: ✭ 114 (-3.39%)
Mutual labels:  npm
Yarn
The 1.x line is frozen - features and bugfixes now happen on https://github.com/yarnpkg/berry
Stars: ✭ 40,325 (+34073.73%)
Mutual labels:  npm
Cli
Get a programmable email address. Automate what happens when you receive emails. It's like Zapier for devs who hate emails.
Stars: ✭ 105 (-11.02%)
Mutual labels:  npm
Npm Stats Www
A website showing npm modules metrics
Stars: ✭ 113 (-4.24%)
Mutual labels:  npm
Npm Stats
📈 npm package statistics dashboard build with vue
Stars: ✭ 106 (-10.17%)
Mutual labels:  npm
Get Programming With Nodejs
Code samples for Get Programming with Node.js (See verhagen's VM setup for exercises in this book: https://github.com/verhagen/get-programming-with-nodejs)
Stars: ✭ 117 (-0.85%)
Mutual labels:  npm
Npm
🚢 semantic-release plugin to publish a npm package
Stars: ✭ 103 (-12.71%)
Mutual labels:  npm
Cheatsheets
A curated list of everything I look up more than twice
Stars: ✭ 109 (-7.63%)
Mutual labels:  npm
Getme
CLI utility for everyday tasks. With getme you get weather, forecast, currency rate, upload files, IP address, word definitions, text translations, internet speed, do google searches, get inspirational quotes and get Chuck Norris jokes
Stars: ✭ 118 (+0%)
Mutual labels:  npm
Sdk Js
Directus JS SDK — JavaScript Software Development Kit for Node and Browser
Stars: ✭ 117 (-0.85%)
Mutual labels:  npm
Rsmq
Redis Simple Message Queue
Stars: ✭ 1,556 (+1218.64%)
Mutual labels:  npm

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 = require('restberry');

restberry
    .config({
        apiPath: '/api/v1',
        port: 5000,
    })
    .listen();

restberry.model('Foo')
    .schema({
        name: {type: String},
    })
    .routes
        .addCreateRoute()
        .addReadManyRoute();

restberry.model('Bar')
    .schema({
        foo: {type: restberry.odm.ObjectId, ref: 'Foo'},
        name: {type: String},
    })
    .routes
        .addCRUDRoutes({
            parentModel: 'Foo',
        });

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": {
    "href": "/api/v1/foos/536f6549e88ad2b5a71ffdc7",
    "id": "536f6549e88ad2b5a71ffdc7",
    "name": "test"
  }
}>
  • 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": {
    "href": "/api/v1/foos/536f654ae88ad2b5a71ffdcb",
    "id": "536f654ae88ad2b5a71ffdcb",
    "name": "test"
  }
}>
  • 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.model('Foo')
    .routes
        .addCreateRoute()  // POST /foos
        .addDeleteRoute()  // DELETE /foos/:id
        .addPartialUpdateRoute()  // POST /foos/:id
        .addReadManyRoute()  // GET /foos
        .addReadRoute()  // GET /foos/:id
        .addUpdateRoute()  // PUT /foos/:id
        .addCRUDRoutes()  // All of the above...

Handle action query strings like this:

restberry.model('Foo')
    .routes
        .addPartialUpdateRoutes({
            actions: {
                build: function(req, res, next) {
                    ...
                },  // POST /foos/:id?action=build
            },
        })

And Handle parent models like this:

restberry.model('Foo')
    .routes
        .addCreateRoutes({
            parentModel: restberry.model('Bar'),
        })  // 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
        .addCustomRoutes({
            action: function(req, res, next) {
                ...
            },
            apiPath: '/api/v1',  // overrides the one set on Restberry
            actions: { },
            loginRequired: false,  // should authenticate the request
            method: 'GET',  // choices: DELETE, GET, POST, PUT
            parentModel: restberry.model('Bar'),
            path: '/path/to',  // the path of the route, will append apiPath
            postAction: function(json, req, res, next) {
                ...
            },  // will be executed after action
            preAction: function(req, res, next) {
                ...
            },  // will be executed before action
            verbose: false,  // will print the API call on initiation
        })

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 [email protected].

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].