Read: Class 07 - 401-advanced-javascript-dania/amman-javascript-401d1 GitHub Wiki
- Routing
Routing refers to how an application’s endpoints (URIs) respond to client requests. For an introduction to routing, see Basic routing.
You define routing using methods of the Express app object that correspond to HTTP methods; for example, app.get() to handle GET requests and app.post to handle POST requests. For a full list, see app.METHOD. You can also use app.all() to handle all HTTP methods and app.use() to specify middleware as the callback function
- Express Routing
-
Event driven system * app.get('/thing', (req,res) => {})
-
The Request Object
- (req,..)
- /:parameters
- app.get('/api/:thing',...) = req.params.thing
- Query Strings
- http://server/route?ball=round = req.query.ball
-
The Response Object
- (..., res)
- Responsible for sending data back to the browser
- Has methods like send() and status() that Express uses to format the output to the browser properly
- Sends Headers
- Cookies
- Status Codes
- Express Middleware A series of functions that the request “goes through”Each function receives request, response and next as parameters Types of middleware: Application and Route Application Middleware
- Error Handling
- Bringing in other routes
- Applies Defaults
- JSON, Body and Form Parsing
- Runs on every request
- Modularization & Separation of Concerns
- Modularizing your code into logical chunks
- Each thing should do the thing its best at
- Dan Abramov: http://react-file-structure.surge.sh/
- CRUD Operations with REST and Express CREATE app.post('/resource') READ app.get('/resource') UPDATE app.put('/resource/:id') DESTROY app.get('/resource/:id')