1.5.4 • Published 7 years ago

micro2-rest v1.5.4

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

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
1.5.4

7 years ago

1.5.3

7 years ago

1.5.2

7 years ago

1.5.1

7 years ago

1.5.0

7 years ago