Skip to main content

Posts

Showing posts with the label request

API's Study Notes: How To Make API Request With Node?

The course shows us we can make API's requests with Node. The first thing we need to do is to create the "APIs" directory and touch "request.js" file inside that folder. Then, we need to npm install request package in the APIs directory. Once we have done those basic steps, we can start to require the "request" and make a request from a JavaScript file. In the request, we need to have the "url" , so the server knows where it should request the API. Next, we need to have a function. request("url", function(error, response, body) In the function, there are three things we pass in: error, response, and body . Error: it will hold any potential error that we get such as internet disconnect, 404, and etc. It is important to check for an error. Response : it will be the incoming message that we receive Body : it is the actual response body that came back like HTML code For example, in the "request.js" ...