From 3d410efc7b0325f94a24fe693c0a1c6dd06c95c7 Mon Sep 17 00:00:00 2001 From: Sahat Yalkabov Date: Fri, 6 Jun 2014 16:48:18 -0400 Subject: [PATCH 1/2] Updated "How do I create a new page" guide --- README.md | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b92ac51f9dc..d86a5eee40d 100644 --- a/README.md +++ b/README.md @@ -793,7 +793,7 @@ exports.isAuthenticated = function(req, res, next) { ``` If you are authenticated, you let this visitor pass through your "door" by calling `return next();`. It then proceeds to the -next middleware until it reaches the last argument, which is a callback function that typically renders a template on `GET` requests or redirects on `POST` requests. In this case, if you are authenticated, then you will see *Account Management* page, otherwise you will be redirected to *Login* page. +next middleware until it reaches the last argument, which is a callback function that typically renders a template on `GET` requests or redirects on `POST` requests. In this case, if you are authenticated, you will be redirected to *Account Management* page, otherwise you will be redirected to *Login* page. ```js exports.getAccount = function(req, res) { @@ -803,7 +803,7 @@ exports.getAccount = function(req, res) { }; ``` -Express.js has `app.get`, `app.post`, `app.put`, `app.del`, but for the most part you will only use the first two. +Express.js has `app.get`, `app.post`, `app.put`, `app.delete`, but for the most part you will only use the first two HTTP verbs, unless you are building a RESTful API. If you just want to display a page, then use `GET`, if you are submitting a form, sending a file then use `POST`. Here is a typical workflow for adding new routes to your application. Let's say we are building @@ -812,9 +812,36 @@ a page that lists all books from database. **Step 1.** Start by defining a route. ```js app.get('/books', bookController.getBooks); - ``` +--- + +**Note:** As of Express 4.0 you can define you routes like so: + +```js +app.route('/books') + .get(bookController.getBooks) + .post(bookController.createBooks) + .put(bookController.updateBooks) + .delete(bookController.deleteBooks) +``` + +And here is how a route would look if it required an *authentication* and an *authorization* middleware: + +```js +app.route('/api/twitter') + .all(passportConf.isAuthenticated) + .all(passportConf.isAuthorized) + .get(apiController.getTwitter); + .post(apiController.postTwitter) +``` + +Use whichever style that makes sense to you. Either one is acceptable. I really think that chaining HTTP verbs on +`app.route` is very clean and elegant approach, but on the other hand I can no longer see all my routes at a glance +when you have one route per line. + +--- + **Step 2.** Create a new controller file called `book.js`. ```js /** From 1615a126791a27ea1be22ee0e70bf58b60603e91 Mon Sep 17 00:00:00 2001 From: Sahat Yalkabov Date: Fri, 6 Jun 2014 16:52:21 -0400 Subject: [PATCH 2/2] Updated 2.2 changelog --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index d86a5eee40d..89d0fc9cb94 100644 --- a/README.md +++ b/README.md @@ -1172,6 +1172,7 @@ Changelog - Added a flash message when user deletes an account - Updated and clarified some comments - Updated the Remove Auth message in `setup.js` +- Cleaned up `styles.less` - Redesigned API Examples page - Updated Last.fm API example - Updated Steam API example