DEV Community

Paramanantham Harrison for JS Mates

Posted on • Originally published at jsmates.com on

How the client request and server response cycle works

Let's learn how the client request flows through the server.

Request response cycle

For understanding, request, and response flow. Let's consider the example of the Twitter home page.

  • If you go to Twitter without logged-in, then it loads generic tweets based on user location.
  • If you log in, then it loads the feeds personalized for you. Even for the same request, different data responses get sent based on the request context.

What exactly happens in-between the client request and server response?

The flow will be like this,

  • Client browser sends a request to the URL – https://twitter.com
  • The server gets the request, parses the request, and checks whether the requested URL is valid or not
  • If not valid, then the server sends a 404 – not found response
  • The server checks whether the request was from valid-user
  • If not a valid user, then it tries to get the user location
  • If it finds the user location, then it sends a response with user location-specific tweet data
  • If it doesn't find the user location, then it sends a response with generic global tweets data
  • If a valid user requested the data, then it sends the response with the user's personalized tweet feed
  • This is how the request flows inside the server before sending a proper response from the server.

This example simplifies a lot of steps in-between to make it easy to understand. There might be many more steps like this before the server sends the response to the client.

Top comments (0)