-
Book Overview & Buying
-
Table Of Contents
Mastering Web Application Development with Express
By :
Express makes use of HTTP verbs and path patterns to provide a meaningful API for describing routes:
app.verb(path, [callback...], callback)
The route handlers take the same arguments (request, response, and next), and the path can be a string (that will be transformed into a regular expression) or a regular expression.
If we were to define a route handler to update an article, then the request method (verb) would be PUT, and the URL could look like /articles/211 (where the number represents the article ID). Here's how to do this with Express:
app.put('/articles/:id', function(req, res, next) {
var id = req.params.id;
console.log('Updating article ' + id);
console.log('Attributes: ', req.body);
// save to database
// send message or render template
});The path parameter can be either a string (transformed into a regular expression internally by Express) or a regular expression, in case we need to match very specific patterns (such as an e-mail address...
Change the font size
Change margin width
Change background colour