Readind 8 Express Routing & Connected API - liz-kavalski-401-advanced-javascript/seattle-javascript-401n13 GitHub Wiki

Using Express Routing

  • Routing refers to how an application’s endpoints (URIs) respond to client requests
  • Define routing using methods of the Express app object that correspond to HTTP methods(like get() and post())
  • Methods specify a callback function (sometimes called “handler functions”) called when the application receives a request to the specified route (endpoint) and HTTP method.
    • Otherwise 'listens' for the request that match it.
  • Can have more than one argument.
    • Needs a next() for more arguments
      • Why?
  • app.all(), used to load middleware functions at a path for all HTTP request methods.
    • a little confused on how this works
  • Route paths, in combination with a request method, define the endpoints at which requests can be made. Route paths can be strings, string patterns, or regular expressions.
  • The characters ?, +, *, and () are subsets of their regular expression counterparts.
  • Hyphen (-) and the dot (.) are interpreted literally by string-based paths.
  • 'Express Route Tester' is a handy tool for testing basic Express routes.
  • Route parameters are named URL segments that are used to capture the values specified at their position in the URL.
  • Can provide multiple callback functions that behave like middleware to handle a request. The only exception is that these callbacks might invoke next('route') to bypass the remaining route callbacks.
    • Can use it as mechanism to impose pre-conditions on a route.
  • The methods on the response object (res) in the following table can send a response to the client, and terminate the request-response cycle.
  • app.route() allows a person to create a chainable route handler.
  • express.Router class to create modular, mountable route handlers. A Router instance is a complete middleware and routing system.

Express Routing

  • Go through how to set it up
  • Express Routing is mini express application without all the bells and whistles of an express application, just the routing stuff
  • Allowed to make our applications more modular and flexible.
  • As a middleware it can check if the user is authenticated, logging data for analytics, or anything else we'd like to do before we actually spit out information to our user.
  • Placements of the middleware and routes is very important.
  • Can have parameters add to it.
  • app.route is basically a shortcut to call the Express Router