i

Handling Get Requests

There are mainly two ways to send data from the client into the server-side:

1. request query string in a GET request

2. request body in a POST request

When a request is sent from the client to the server, the data will be attached to the request URL. To retrieve data on the server-side, we need to handle the GET request.

In node.js, we have url and querystring modules to handle the GET requests.

We use the request object at the server-side to get the request and get the data sent from the client to the server.

For this

1. we will first import url and querystring modules to retrieve data from request url.

2. Create a server and use the data as required (For Authentication or find the page requested).

getRequestDemo.js

Running the Server

Browser

When sending the request to port 5200 for server
with id=warren and password=buffet

It sends the request to the server running at port 5200.

In the code snippet, url and the querystring modules are loaded and 

url.parse() method is used to parse the request URL and then to get the querystring from the URL; the query property is used.