Learn Express Routes
Lesson 1 of 3
  1. 1
    A huge portion of the Internet’s data travels over HTTP/HTTPS through request-response cycles between clients and servers . Every time that you use a website, your browser sends requests to one or…
  2. 2
    Express is a Node module, so in order to use it, we will need to import it into our program file. To create a server, the imported express function must be invoked. const express = require(‘expres…
  3. 3
    Once the Express server is listening, it can respond to any and all requests. But how does it know what to do with these requests? To tell our server how to deal with any given request, we register…
  4. 4
    HTTP follows a one request-one response cycle. Each client expects exactly one response per request, and each server should only send a single response back to the client per request. The client is…
  5. 5
    Express tries to match requests by route, meaning that if we send a request to : /api-endpoint, the Express server will search through any registered routes in order and try to match /api-endpoint…
  6. 6
    Routes become much more powerful when they can be used dynamically. Express servers provide this functionality with named route parameters. Parameters are route path segments that begin with : in…
  7. 7
    Express allows us to set the status code on responses before they are sent. Response codes provide information to clients about how their requests were handled. Until now, we have been allowing t…
  8. 8
    Parameters are extremely helpful in making server routes dynamic and able to respond to different inputs. Route parameters will match anything in their specific part of the path, so a route matchin…
  9. 9
    HTTP Protocol defines a number of different method verbs with many use cases. So far, we have been using the GET request which is probably the most common of all. Every time your browser loads an…
  10. 10
    You may have noticed in the previous exercise that our PUT route had no information about how to update the specified expression, just the id of which expression to update. It turns out that there …
  11. 11
    Express matches routes using both path and HTTP method verb. In the diagram to the right, we see a request with a PUT verb and /expressions (remember that the query is not part of the route path). …
  12. 12
    POST is the HTTP method verb used for creating new resources. Because POST routes create new data, their paths do not end with a route parameter, but instead end with the type of resource to be cre…
  13. 13
    DELETE is the HTTP method verb used to delete resources. Because DELETE routes delete currently existing data, their paths should usually end with a route parameter to indicate which resource to de…
  14. 14
    Congratulations, you have made our glorious Express Yourself Machine fully operational! Not only that, you now have all the tools you need to create a basic CRUD API! Time to practice your skills…
  15. 15
    In this exercise, you were able to create a full server allowing users to implement all CRUD operations for two kinds of resources: Expressions and Animals! With these skills and knowledge of the H…

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory