DEV Community

Jarvish John
Jarvish John

Posted on

How a request originates from client and reaches the server

How it Fetches the IP through DNS

What is DNS?

Before starting, let's be clear about what DNS is. DNS (Domain Name System) is like a system that maps a domain name to its corresponding IP address, making it easier for users to access websites without remembering numerical IPs.


Example Scenario

Let’s say we are searching for "WIKIPEDIA".


Step 1: Checking Local Cache

First, the machine checks within itself (browser/cache), asking, "Do you remember the IP of Wikipedia?"
If it finds the IP, the process stops here and the request proceeds directly to the server.


Step 2: Forwarding the Request

If it doesn’t find it in the cache, the request is forwarded to the router/modem.
If it still doesn’t know, it is sent to the resolver (Internet Service Provider).


Step 3: Querying DNS Servers

If the resolver also doesn’t have it cached, it queries the Root Name Server.
From there, it is directed to the appropriate Top-Level Domain (TLD) server like .com, .in, or .org.
Then it reaches the authoritative name server, where it finds Wikipedia’s IP from the zone file.


Step 4: Returning the IP Address

Finally, the IP address is returned back to the user and stored in cache for faster access in future requests.


What Happens After DNS Resolution?

Once the IP address is obtained through DNS, a connection is established between the client and server using TCP. If the communication is secure (HTTPS), TLS encryption is also used.

After the connection is established, the client sends an HTTP request to the server.


HTTP Methods Used in API

Common Methods

GET, POST, PUT, PATCH, DELETE


Explanation of Each Method

GET is used to fetch data from the server.

POST is used to create new data or resources on the server.

PUT is used to update or replace the entire resource.

PATCH is used to partially update the data without modifying the entire resource.

DELETE is used to remove the data from the server.


Server Response and Rendering

After receiving the request, the server processes it and sends back an HTTP response. This response contains a status code (like 200 OK), headers, and the requested data.

The browser then interprets this response and renders the webpage for the user.


Idempotency

What is Idempotency?

Idempotency means performing the same operation multiple times results in the same outcome as performing it once.


Idempotent vs Non-Idempotent Methods

GET, PUT, and DELETE are idempotent because repeating them does not change the result beyond the initial request.

POST is not idempotent because multiple requests can create multiple resources.

PATCH depends on how it is implemented and may or may not be idempotent.

Top comments (0)