micro2-rest

1.5.4 • Public • Published

micro2-rest is middleware for serve rest api request.

NPM Version Code Climate issues license

const http = require("http");
const rest = require("micro2-rest");
 
rest.use('/', {
    get: function(req, res, done) {
        done({
            url: req.url,
            method: req.method,
        });
    },
    post: function(req, res, done) {
 
    }
}, (err, req, res, next) => {
    if (err) res.end(err);
    next();
});
 
rest.use('/post/:id(\\d+)', {
    get: function(req, res, done) {
        done({
            url: req.url,
            method: req.method,
            data: {
                a: 10
            }
        });
    },
    post: function(req, res, done) {
        done({
            url: req.url,
            method: req.method,
        });
    }
}, (err, req, res, next) => {
    if (err) res.end(err);
    next();
});
 
const server = http.createServer(function(req, res) {
    rest()(req, res);
});
 
server.listen(3000);

Getting Started

micro2-rest is middleware for serve rest api request.

Install

$ npm install micro2-rest

Package Sidebar

Install

npm i micro2-rest

Weekly Downloads

0

Version

1.5.4

License

MIT

Last publish

Collaborators

  • rjoydip