micro2-rest
v1.5.4
Published
This is a REST middleware node.js.
Downloads
1
Maintainers
Readme
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