Technology
Web servers, APIs, and REST/GraphQL

How the Web Speaks? Web Servers, APIs, REST, and GraphQL
You do not simply press a button when you check out of an e-commerce site. You are causing a complicated dialogue between your computer and a computer thousands of miles away. This is magic to an average user. It is a particular sequence of tokens to a developer, with three key and central actors, Web Servers, APIs, and the languages in which these speak, usually either REST or GraphQL.
Demystifying this backend infrastructure.
1. The Web Server - The Host
Fundamentally, a Web Server is computer software (and hardware component thereof) which contains files of websites (HTML, CSS, images) and data. Consider the Restaurant as the web server. It contains the tables and the kitchen (database). Its major duty is to hear out orders by the customers (browsers) and deliver to them what they order. Popular ones include Nginx, Apache and Microsoft IIS. The code will remain on a hard drive and your code is nothing without a web server that will make it visible to the world.
2. The API - The Interface
Application Programming Interface is abbreviated as API. Where in case the server is the restaurant, the API is the Menu. You do not enter the restaurant kitchen and begin to cook your meal (communication with the database). That would be anarchy and insecure. Rather, you consider the menu (the API), which contains nothing other than what is offered "Get User Data," "Post New Comment," or "Delete Photo." The API acts as the messenger. It forwards your request, informs the system of what you desire to do and then it sends back the response. The layer of security and abstraction is what enables various software systems to communicate in a safe manner.
3. REST vs. GraphQL - The Request Language.
The Restaurant (Server) and the Menu (API) therefore. But what do you really do to make your order? This is where REST and GraphQL debate takes place. These are architectural frameworks of constructing APIs.
The REST (Representational State Transfer)
The traditional, standard method is REST. It employs the common HTTP operations (GET, POST, PUT, DELETE) and separate URLs (endpoints) of the various resources.
- How it works? Visit /users/1 to obtain the profile of a user. In order to access their posts, you access /users/1/posts.
- The Downside? It can either Over-fetch or Under-fetch (it depends on whether it received too much data (like downloading entire user profile when you just needed their name) or had to make 5 different calls to 5 different endpoints to load one page).
GraphQL
GraphQL is the newcomer developed by Facebook. It does not consider data as a list of files, but a graph.
- How it works? It consists of a single endpoint. You make a certain request with the following instruction, I want the User with the ID 1, but only provide me with his/her name, and the 3 latest post titles.
- The Pros You can request the data you want, no more and no less, in one request.
The Verdict
REST is easy, intensely robust and very cacheable. It works well with simple applications and open APIs. GraphQL is adaptable and effective. It works best with complex frontends with rich data needs (such as facebook or instagram) in which mobile bandwidth is valuable. It is necessary to know the three layers - the Server hosting, the API connecting, and the Language (REST/GraphQL) communicating to comprehend the backend development.
Test Your Knowledge!
Click the button below to generate an AI-powered quiz based on this article.
Did you enjoy this article?
Show your appreciation by giving it a like!
Conversation (0)
Cite This Article
Generating...


