Getting ready

Understanding routing is one of the most important core aspects in building robust RESTful APIs.

In this recipe, we will see how ExpressJS handles or interprets HTTP requests. Before you start, create a new package.json file with the following content:

{ 
    "dependencies": { 
        "express": "4.16.3" 
    } 
} 

Then, install the dependencies by opening a Terminal and running:

    npm install
  

ExpressJS does the whole job of understanding a client's request. The request may come from a browser, for instance. Once the request has been interpreted, ExpressJS saves all the information in two objects:

  • Request: This contains all the data and information about the client's request. For instance, ExpressJS parses the URI and makes its parameters available on request.query.
  • Response: This contains data and information that will be sent to the client. The response's headers can be modified as well before sending the information to the client. The response object has several methods available for sending the status code and data to the client. For instance: response.status(200).send('Some Data!').
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.135.67