Request-Response Cycle.

Abinash Panda
4 min readJan 24, 2020

If you request something on the internet lets say altcampus.io and you receive a web page on your screen. But how this works? let me walk through briefly.

Client:

Any device which can speak to a web server is called the client it maybe your laptop, mobile, tablet, smartwatch etc uses application like browser, terminal or any native app to communicate to a web server client uses standard internet protocols.

Protocols:

Protocol means a set of rules. To access the internet our device/application uses different types of protocols to communicate. There are different types of protocols each one has its own use cases with both advantages and disadvantages. Here are common protocols.

HTTP: HyperText Transfer ProtocolHTTPS: HyperText Transfer Protocol SecureSSH: Secure ShellFTP: File Transfer ProtocolSMTP: Simple Mail Transfer ProtocolTCP:Transmission Control ProtocolUDP: User Datagram ProtocolWebSocket

HTTPS is the encrypted version of the HTTP protocol. So things like online banking or exchange some sensitive data can be more secure.

when we request something with HTTP protocol we use request methods but the most common one is GET, POST, PUT, PATCH, DELETE.

  • ‘GET’: This method uses the client for requesting data.
GET www.blog.com/myblog
  • ‘POST’: This method uses the client for sending data.
POST www.blog.com/user/createprofile:{
"username":"sam",
"city":"LA"
}
  • ‘PUT’: This method uses the client for updating data.
profile:{
"username":"sam",
"city":"LA"
}
PUT www.blog.com
Profile:{
"username":"sam",
"city":"NYC"
}
  • ‘PATCH’: This method uses the client for updating data but the patch is different then put
profile:{
"username":"sam",
"city":"LA"
}
PUT www.blog.com
Profile:{
"city":"NYC"
}
  • “DELETE”: This method is uses the client to delete something.
DELETE www.blog.com/profile

Response status code:

  • (100 — 199) Informational responses.
  • (200 — 299) Successful responses.
  • (300 — 399) Redirects.
  • (400–499) Client errors.
  • (500–599) Server errors.

Server:

A web server is a computer very similar to your PC but the job of a web server is to listen to the request and respond to it. It has storage or database in which a server can perform CRUD(Create, Read, Update, Delete) operations. Depend on the application a web server can serve static file(web pages which do not change), media files like images, videos and music or it can give you JSON file.

Again we request something lets say https://www.altcampus.io/students
in this case :

  • https is the scheme.
  • www(world wide web) is the subdomain but it can be different like mail.google.com in this case ‘mail’ is the subdomain.
  • altcampus is the domain name.
  • In the upper example, ‘io’ is the top-level domain. Other like ‘com’ fro commercial, ‘org’ for organizations, ‘edu’ for educational institutions, ‘gov’ for a government body, and country-specific domain-like ‘in’ for India, ‘id’ for Indonesia.
  • in a URL path may contain like upper example ‘/students ’ is the path.
  • In a URL we can pass a query like this ‘https://github.com/ReactTraining/react-router?ref=HackerTabExtension’ after ‘?’ the query begins.
  • we can also pass fragment after ‘#’ this can use a specific part of a page.

A controller can be configured in many ways like nodeJS, PHP, Ruby, GO, Apache, Nginx.

The most web applications use MVC(Model View Controller) architecture which looks like the image below.

Ports:

On Wikipedia In computer networking, a port is a communication endpoint. At the software level, within an operating system, a port is a logical construct that identifies a specific process or a type of network service. Ports are identified for each protocol and address combination by 16-bit unsigned numbers, commonly known as the port number. The most common protocols that use port numbers are the Transmission Control Protocol (TCP) and the User Datagram Protocol (UDP).

  • One device can have up to 65,535 ports, most ports are closed because of security reasons.
  • Some ports are reserved as default port like HTTP default port is 80 and HTTPS default port is 443.

IP, DNS, & Routers:

So you request something on the internet and the server response with some data but there are millions of the server which are connected to the internet to solve this problem the ISP(Internet Service Provider) is assigned an IP address to connected devices but you don't have to remember those IP address when you enter a domain name it goes to DNS server to bring the IP address of the corresponding domain.

So IP address is work like address and when you send something routers are there to forward your request. Let's say the server is in Bangalore, India and you are somewhere in Indonesia requesting a cat image the request-response is goes through the router to reach the destination.

There are two types of IP addresses

  • IP v4 ex. ‘192.168.33.77’
  • IP v6 ex. ‘2001:db8:85a3:8d3:1319:8a2e:370:7348’

why we need IP v6? because we can create only ‘4,294,967,296’ Ip and we have way more device is connected that's why IP v6 is created.

Thanks for reading. Any feedback is welcome.

--

--