In modern web development, the architecture of web applications is typically divided into front-end and back-end parts. The front-end refers to everything the user interacts with directly, while the back-end is responsible for processing requests, storing data, and ensuring everything works behind the scenes.
This README will explain the client-server relationship and the core technologies that make the request-response cycle happen, focusing on the server-side components.
The front-end is the code that is executed on the client side. This code (typically HTML, CSS, and JavaScript) runs in the user’s browser and creates the user interface. It interacts with the back-end through HTTP requests and displays the data returned by the server.
The back-end is the code that runs on the server, processes requests, and manages the data. It typically includes:
- The Server: The machine that listens for requests.
- The App: The software running on the server that processes requests.
- The Database: Stores and retrieves data.
Clients are anything that sends requests to the back-end. While browsers are the most common clients, they can also be mobile applications, server-side applications, or even web-enabled smart appliances.
A back-end is the technology responsible for processing incoming requests and generating appropriate responses. It includes:
- The Server: A machine that receives requests from clients.
- The App: An application on the server that handles incoming requests, queries the database, and sends responses.
- The Database: Stores persistent data for the application.
A server is a computer that listens for incoming requests from clients. While specialized servers exist, any computer connected to a network can act as a server, especially during development.
The app running on the server listens for requests and matches them to routes, which consist of an HTTP verb and a URI (Uniform Resource Identifier). This process is known as routing.
- Middleware: Code executed between receiving a request and sending a response. Middleware can modify the request, query the database, or process the request in other ways.
Eventually, a middleware function sends an HTTP response back to the client, ending the request-response cycle.
A server can send different types of responses:
- HTML files
- JSON data
- HTTP status codes (e.g., 404 for "Not Found")
Databases are used on the back-end to persist data. They provide an interface to store and retrieve data, reducing the load on the server's main memory and ensuring data is saved even if the server crashes.
Many requests involve querying the database to retrieve or store data.
A Web API is a collection of endpoints that define how a server communicates with clients. It specifies:
- Routes: The paths through which the server communicates with clients.
- Responses: The data the client receives when hitting a route.
Web APIs allow different front-end applications to interact with the same back-end without needing to know the specifics of how the data is presented.
- The server cannot initiate responses without requests: The server only responds to requests from clients.
- Every request needs a response: If the server does not respond, the client will be left waiting indefinitely.
- Only one response per request: A server should not send multiple responses for a single request.
Alice is shopping on SuperCoolShop.com. She clicks on a product picture, which sends a GET request to: http://www.SuperCoolShop.com/products/66432
The request is asking for data about the product with ID 66432.
The request travels through the internet and reaches one of SuperCoolShop’s servers. The server listens for incoming requests and processes them accordingly.
The server triggers the event listeners based on the GET verb and the /products/66432 URI. Middleware functions handle the request, potentially querying the database for the product information.
The server makes a database query to retrieve information about the smartphone case (e.g., name, price, reviews).
Once the server receives the data from the database, it constructs a response containing the requested information (e.g., product name, price, image, reviews).
The server sends the response back to Alice’s browser. The response includes an HTTP status code 200, indicating success.
The response travels back through the internet to Alice’s computer.
Alice’s browser receives the response and uses the data to render the product details on her screen.
This cycle repeats for every request made to the server, allowing users to interact with dynamic web applications. Understanding the client-server relationship and how the back-end processes requests is fundamental to building scalable and efficient web applications.
For more in-depth information, review the HTTP and REST concepts.