How 🤷‍♂️ a web server 🖥 works?
By: Watch Online Free Tv Boxing
Tags: Database, Rest Api, Servers, System Design Project, Https

Request

Method Host/IP Request Headers Body Path Query Params HTTP Version Scheme

1. Method

Assume it as the operation you want to perform. If you want to fetch/get some posts from the server, then you use GET method for that, likewise for deleting a post, the DELETE method. Here is a list of methods we use most often.

GET, PUT, POST, PATCH, DELETE

2. Host/IP

Basically when you get a server from hosting providers like Digital Ocean, Linode etc., they don’t give you something like fayaz.com, but they can give you only the IP address of the server, something like 104.54.74.5 🖥 which holds connection to the server, it’s your task to get a domain from DNS(Domain Name Server) providers like GoDaddy, NameCheap etc., and then make mapping to the server. (You can find detailed instructions from the hosting provider’s website, we will discuss deeply about this later).

3. Headers

Headers are like informative key-value pairs, which will introduce the API request to the server. Didn’t get an idea? Think about something like a phone call, whenever someone call you, their phone number is visible on your screen which makes easy for you to understand who is calling you, from which country… Here you’ll something similar, just look at common request headers below.

Common Request headers:

Authorization

Content-Length

Content-Type

Accept

Let’s consider an Authorization header, generally in OAuth 2.0 protocol we use this header in two ways, one to access(Bearer) the API and other to refresh our token(Basic). Take a look at below example which demonstrates how we use headers and tokens in OAuth 2.0,

OAuth 2.0 using Tokens and accessing API using Tokens

Here, I am using the JSON, content type to exchange data so we should add the headers:

Content-Type: application/json to tell the server how to read the values as json, Accept: application/json to tell the server send response as json

4. Body

This is the place where a server and client exchange the actual data. Consider the above example, in the first request there we are sending username and password in json format. And in the third request, we are getting user details in the same json format. We can send data in any format, developers also used to send data as plain text, xml before.

5. Path

As the name of it, it’s quite the same thing. The path where we want to communicate with the server. Consider a sample API which has two paths configured, users and posts respectively.

We make requests to respective paths to get the correct data. When we call the users path, it will return us the users data available in db and posts will return posts available in the db. We’ll consider the example at the end of this section.

6. Query

This is similar to body, but key-value pairs which are directly send in the request url. Consider example at the end of this section.

7. Params

This is similar to query field, but without any key and sent along the path following a slash(/). Consider example at the end of this section.

8. HTTP Version

We don’t have to worry much about this as a beginner, generally most of the API’s run on HTTP/1.1 or HTTP/2. This will be considered during the configuration of the web server.

9. Scheme

This is related to the Transport layer security, if we don’t have an SSL certificate, our scheme will be HTTP and if we have SSL, then it will be HTTPS. It is recommended to use https scheme in production level API as it provides end-to-end encryption and decryption. Feel free to get more information about SSL on the internet.

Request showing usage of path params

Here we are trying to make a request to the server, which should return the user’s data whose id is 37ded9815cb3. The API path ends as api/v1/user but the id which we sent as considered as param and the server configuration will be something like this api/v1/user/:userId . If the server is configured as the above way, then it identifies the id which we sent as userId for the above request. They are considered as path-params.

Request showing query params