Socket
Book a DemoInstallSign in
Socket

cottage-barney

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cottage-barney

you can make restful api router, easier with Barney

0.1.9
latest
Source
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source


you can make restful api router, easier with Barney

Decription

Cottage-Barney is a restful api router made with therne/cottage. this router support middleware, HTTP status, URI param, and etc..

Get started

Installation

$ npm install --save cottage-barney

Example

const cottage = require('cottage');
const Router = require('cottage-barney');

const app = cottage();
const router = new Router(app);

class Index {
    // this.params => URI params object like '/:id'
    // this.query => GET query object
    // this.req => koa.Request
    // this.req.body => Body object
    // this.res => koa.Response

    get() {
        // Do something!
        this.res.status = Router.status.OK; // We're support http status code's with 'david/http-status'
        return 'GET METHOD';
    }
    post() {
        // Do something!
        return 'POST METHOD';
    }
    delete() {
        // Do something!
        return 'DELETE METHOD';
    }
}

router.set('/', new Index());
router.set('/what/:id', new Index()); // barney also support uri param

app.listen(8080);

Middleware Usage

const cottage = require('cottage');
const Router = require('cottage-barney');

const app = cottage();
const router = new Router(app);

const middleware = function(router) { // 1 argument is required
    router.res["status"] = Router.status.CREATED; // You can handling resposne, request, params, query
};

router.use(middleware);
router.set('/', new Route());

/*
Middleware can use with children.
router.set('', {}, [
    {
        path: '/',
        route: new Route(),
        middlewares: [
            function(route) {
                // You can use middleware like this
                console.log("This is index!");
            }
        ]
    }
]);
 */

app.listen(8080);

Documentations

  • API Documentation TBA
  • Samples TBA

License : MIT

Keywords

router

FAQs

Package last updated on 05 Jun 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.