Closed rosenfeld closed 9 years ago
the code in regular express is like that.
// respond with "Hello World!" on the homepage
app.get('/', function (req, res) {
res.send('Hello World!');
})
// accept POST request on the homepage
app.post('/', function (req, res) {
res.send('Got a POST request');
})
// accept PUT request at /user
app.put('/user', function (req, res) {
res.send('Got a PUT request at /user');
})
// accept DELETE request at /user
app.delete('/user', function (req, res) {
res.send('Got a DELETE request at /user');
})
where in router.js(use puer) is equals to
module.exports = {
// respond with "Hello World!" on the homepage
"GET /": function(req, res){
res.send('Hello World!');
},
// accept POST request on the homepage
"POST /":function(req,res){
res.send('Got a POST request');
},
// accept PUT request at /user
"PUT /user": function(req, res){
res.send('Got a PUT request at /user');
},
// accept DELETE request at /user
"DELETE /user": function(){
res.send('Got a DELETE request at /user');
}
}
puer translate the data-struture to regular express router.js
Why do that?
beacuse, puer need to hot-reload the route.js once the [file route.js] is changed. If the route.js is export regular javascript( shown in the top), puer can't safely reload the route related logic in the memory.
Hope my poor english doesn't hurt you :)
My concerns are that some people (like me) do not program themselves in Express.js or even Node.js and would be interested on this server like a tool. So basically we need to understand how to create basic responses for our tests and it's hard to follow the documentation in README since it points to Express.js which documents it in a different way. Maybe it would be enough to explain how to translate Express.js examples to puer. For instance, it's not documented how one would change the HTTP response headers or read the request headers.
@rosenfeld convincing suggestion. document about router will be add soon
Thanks :-)
I add some example about routing with express.Router in puer .
Excelent, thanks! :)
The README mention it follows express.js routes.js specification but it seems the given examples in the README are different from the examples in the documentation:
http://expressjs.com/starter/basic-routing.html
Could you please point to the specific documentation you were referring to or at least change the examples in the README to be like the ones in the Express.js documentation site?