Created
February 23, 2012 23:29
-
-
Save arpunk/1895690 to your computer and use it in GitHub Desktop.
restify
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var restify = require('restify'); | |
var server = restify.createServer(); | |
server.get('/hola/mundo/:nombre', function(req, res) { | |
res.send(200, { | |
message: req.params.nombre + ' le dice hola mundo a todos!' | |
}); | |
}); | |
server.listen(9001); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var restify = require('restify'); | |
var options = { | |
certificate: Archivo | |
key: Archivo | |
formatters: { | |
'application/foo': function(req, res, body) { ... } | |
}, | |
log: Objeto | |
name: "ejemplo" | |
version: "1.2.3" | |
} | |
var server = restify.createServer(options); | |
server.listen(9002); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var restify = require('restify'); | |
var server = restify.createServer(); | |
server.use(restify.acceptParser(server.acceptable)); | |
server.use(restify.authorizationParser()); | |
server.use(restify.dateParser()); | |
server.use(restify.queryParser()); | |
server.use(restify.jsonBodyParser()); | |
server.use(restify.urlEncodedBodyParser()); | |
function pre1(req, res, next) { console.log('pre1'); return next(); }; | |
function pre2(req, res, next) { console.log('pre2'); return next(); }; | |
function post1(req, res, next) { console.log('post1'); return next(); }; | |
function handler(req, res, next) { | |
res.send({ | |
params: req.params.id | |
}); | |
}; | |
function handler2(req, res, next) { res.send({ params: req.params }) }; | |
server.head('/foo/:id', [pre1], handler, [post1]); | |
server.get('/foo/:id', [pre1, pre2], handler, [post1]); | |
server.post('/foo', [pre1, pre2], handler2, [post1]); | |
server.put('/foo/:id', [pre1, pre2], handler, [post1]); | |
server.del('/foo/:id', handler); | |
server.on('NotFound', function(req, res) { | |
res.send(404, req.url + ' no se encontró'); | |
}); | |
server.on('MethodNotAllowed', function(req, res) { ... }); | |
server.on('VersionNotAllowed', function(req, res) { ... }); | |
server.on('after', function(req, res) { ... }); | |
server.listen(9003); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment