apiController for second express example
module.exports = function(app) { | |
// This contains all of the endpoints that return views/html. | |
// The function takes an app object and adds the endpoints | |
// to the app. | |
app.get('/', function(req, res) { | |
res.send('<html><head><link href=assets/style.css type=text/css rel=stylesheet /></head><body><h1>Donuts</h1></body></html>'); | |
}); | |
app.get('/form', function(req, res){ | |
res.sendFile(__dirname + '/form.htm'); | |
}); | |
app.get('/person/:id', function(req, res) { | |
res.send('<html><head></head><body><h1>Donuts for Person ' + req.params.id + '</h1></body></html>'); | |
}); | |
app.post('/person', urlencodedParser, function(req, res){ | |
res.send('Thank you!'); | |
console.log(req.body.firstname); | |
console.log(req.body.lastname); | |
}); | |
app.post('/personjson', jsonParser, function(req, res){ | |
res.send('Thankyou for the json data'); | |
console.log(req.body.firstname); | |
console.log(req.body.lastname); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment