0. Introduction
Client–Server Architecture
The client–server architecture is a distributed application structure that divides workloads between service providers (servers) and service consumers (clients).
- A service is an abstraction over computing resources.
- A server hosts one or more server programs and exposes services to clients.
- Clients request services and servers process those requests.
- The most common communication stack is TCP/IP.
- Examples of client–server applications include email systems, network printing systems, and the World Wide Web.
Client and Server Communication
Clients and servers exchange messages using a request–response communication pattern.
- A protocol is a set of rules that allows computers to communicate.
- The client sends a request.
- The server processes the request and returns a response.
- The client interprets the response according to the protocol.
- Servers often expose an Application Programming Interface (API), which defines how clients can access a service.
World Wide Web
The World Wide Web is built on top of the HTTP protocol.
HTTP
HTTP (Hypertext Transfer Protocol) is:
- Stateless.
- Text-based.
- Request–response oriented.
- Based on the client–server model.
Because HTTP is stateless, every request is independent from previous requests.
HTTP was created in conjunction with HTML standard.
HTML
HTML (HyperText Markup Language):
- Describes the structure of web pages.
- Allows documents to contain links to other documents.
- Allows the embedding of images, videos and other media content, while HTTP is used to retrieve the content referenced in an HTML document.
Web Browsers
End users access the World Wide Web through web browsers. A web browser sends HTTP requests to web servers in order to retrieve web resources identified by URLs. These resources include HTML documents, images, videos, style sheets, and other content that the browser interprets and displays to the user.
URLs
A URL (Uniform Resource Locator) is a name that identifies the location of a resource on a network.
General format:
protocol://host:port/path/file
Example:
http://www.football.com:80/leagues/premier_league_2020.html
Components:
- Protocol:
http - Host:
www.football.com - Port:
80 - Path:
/leagues/ - Resource:
premier_league_2020.html
MIME Types
HTTP can transfer any content type identified by a MIME type, such as:
- text/html
- application/json
- image/png
- application/pdf
1. What Is a Web Application?
A web application is software accessed through a web browser.
A web application consists of:
Front-End (Client Side). It runs inside the browser. Its responsibilities includes: displaying user interfaces, capturing user input and sending requests to the back-end. It uses technologies such as HTML, CSS and JavaScript
Back-End (Server Side). It runs on application servers. Its responsibilities includes: processing requests, executing business logic, accessing databases and generating responses.
A back-end application serves many users simultaneously. Multiple requests may execute concurrently, so server-side applications must be designed to handle concurrent execution safely.
URL vs URI
A URI (Uniform Resource Identifier) identifies a resource.
A URL is a specific type of URI that also specifies how to locate the resource.
For examples, https://example.com/users/10 is both a URI and a URL.
A URL is a type of URI, a URI is not always a URL.
In modern REST APIs, developers commonly refer to endpoint paths as URIs.
Different Ways to Implement Web Applications
There are two different approaches to design web application
Traditional Web Applications
- There is not front-end back-end separation
- the back-end serves a complete view in response to each client request.
- The server returns data formats such as HTML, CSS, JavaScript and images.
Workflow:
Browser --> Request --> Server
Browser <-- HTML page <-- Server
Examples: Spring MVC with Thymeleaf, JSP applications
Modern Web Applications
- The front-end and back-end are separated.
- The browser runs a JavaScript front-end application, loaded from the server at the first request.
- The front-end application calls APIs and receives raw data in JSON or XML formats
- The front-end interprets the data and builds the user interface dinamically.
Workflow:
Browser --> API Request --> Server
Browser <-- JSON/XML <-- Server
Examples: React/Angular/Vue with a Spring Boot REST API.
Using a Servlet Container
What Is a Servlet Container?
A servlet container:
- Receives HTTP requests.
- Converts HTTP messages into Java objects.
- Executes servlets.
- Sends HTTP responses.
Popular servlet containers:
- Apache Tomcat
- Jetty
- Undertow
What Is a Servlet?
A servlet is a Java class managed by the servlet container.
The container invokes servlet methods and provides HttpServletRequest and HttpServletResponse objects.
Spring Web Applications and the Dispatcher Servlet
A Spring MVC application does not require developers to create servlets for every endpoint.
Instead, Spring registers a single servlet, the DispatcherServlet.
The DispatcherServlet acts as the application's Front Controller.
Every HTTP request follows this path:
Client
↓
Tomcat
↓
DispatcherServlet
↓
Controller
↓
View / Response
This design is known as the Front Controller Pattern.
No comments:
Post a Comment