Compiled on: 2026-05-19 — printable version
The Web is, at the same time:
In practice, the Web revolves around:
https://example.com/getCustomer?id=123https://example.com/customers/123Hyper-Text Transfer Protocol (HTTP) standardizes how clients and servers exchange messages:
123), hosted by server at https://example.comhttps://example.com/speakers/123/volume
GET [“I want to read some information about the resource”]Accept: text/html [“I want the response to be an HTML page describing the volume”]Authorization: <auth token here> [“I am authorized to access this resource, here is my token”]200 OK [“The request was successful, here is the information you asked for”]Content-Type: text/html [“The body of this response is an HTML document”]Cache-Control: no-cache [“Don’t cache this response, it may change frequently”]<html><body><h1>Speaker 123</h1><p>Volume: 75%</p></body></html> [“Here is the HTML page describing the speaker’s volume”]123), hosted by server at https://example.comhttps://example.com/speakers/123/volume
POST [“I want to change some information about the resource”]Content-Type: application/json [“The body of this request is a JSON document describing the change I want to make”]Authorization: <auth token here> [“I am authorized to access this resource, here is my token”]{"change": "+10%"} [“I want to increase the volume by 10%”]204 No Content [“The request was successful, but there is no content to return in the body”]
Standard set of admissible operations that clients may request on resources:
main ones: GET, POST, PUT, PATCH, DELETE

many more are supported, for example HEAD, OPTIONS, CONNECT, TRACE, etc.
3-digit, positive integer numbers, the most significant digit identifying the class of the response:
1xx: informational responses (e.g., “time to swap to another protocol”)2xx: successful responses (e.g. “successfully processed the request with/without body being returned”)3xx: redirection messages (e.g. “the resource has moved, here is the new URL”)4xx: client-side error responses (e.g. “cannot process the request due to client’s mistake”)5xx: server-side error responses (e.g. “cannot process the request due to server’s mistake”)most common status codes are in the picture:
Key–value pairs that carry metadata about the request or response, for example:
Content-Type: specifies the media type of the body content [both in reqs and resps]Authorization: contains credentials for authenticating the client [commonly in reqs]Cache-Control: provides directives for caching mechanisms [commonly in resps]Accept: indicates the media types that the client can process [commonly in reqs]Set-Cookie: instructs the client to store a cookie [commonly in resps]User-Agent: identifies the client software making the request [commonly in reqs]Location: indicates the URL of a newly created resource or a redirection target [commonly in resps]Server designers may “invent” custom headers, but it’s best to stick to standard ones when possible for better interoperability
X- to avoid conflicts with standard headers
MyApp-) for non-standard headers.URL query parameters (e.g., ?page=2&sort=asc) are used to pass additional information to the server, often for filtering, sorting, or specifying options for the requested resource
GET /products?page=2&sort=asc)Syntactical aspects:
? [and precedes #, if present] in the URL”key=value pairs, separated by & (e.g., ?key1=value1&key2=value2)%20)
% followed by two hexadecimal digits representing the ASCII code of the characterCommon query parameters include:
page for pagination, indicating which page of results to retrieve, assuming the server knows how to group data into pages (e.g., ?page=2)limit for limiting the number of results returned (e.g., ?limit=10)offset for specifying the starting point of results (e.g., ?offset=20)sort for sorting (e.g., asc or desc)filter for filtering (e.g., ?filter=price>100)search for search queries (e.g., ?search=keyword)Authorization)?query=search+term)Clients and servers may automatically negotiate the format of the data being exchanged
Accept header listing the media types it can process, possibly with quality values (e.g., Accept: text/html, application/json;q=0.9, */*;q=0.8)Content-Type header indicating the media type of the body (e.g., Content-Type: application/json)text/html, application/json, image/png, etc.)MIME stands for “Multipurpose Internet Mail Extensions”, but it is used far beyond email to identify media types in HTTP and other protocols
A MIME type consists of a type and a subtype, separated by a slash (e.g., text/html, application/json, image/png)
Full list is available at https://developer.mozilla.org/docs/Web/HTTP/Guides/MIME_types/Common_types
Most common MIME types are in the table below:
Hypertext Markup Language (HTML): text/html (for Web pages) should describe the content of a Web page, with no stylistic or behavioural information
“the page” usually represents some resource (physical, digital, or virtual) that exists on the server-side, in a human-friendly way
it may contain links to other resources (e.g. media, other pages, scripts, etc.)
it may contain forms to let users interact with the server (e.g. submit data, trigger actions, etc.)
it may contain identifiers (e.g. id attributes) and classes for page contents (e.g. paragraphs, buttons, etc)
underlying assumption is that the client knows how to render HTML pages…
example of HTML page describing a speaker resource:
<html>
<body>
<h1>Speaker 123</h1>
<p>Volume: 75%</p>
<button id="increase-btn">Increase Volume</button>
</body>
</html>
Cascading Style Sheets (CSS): text/css (for stylesheets) should describe the styling of a Web page, with no content or behaviour information
it may contain rules about how to depict individual elements or groups of elements of the page (as identified by their tag, id, class, etc.)
these rules are interpreted by the client to determine how to render the page (e.g. colors, fonts, layout, etc.)
example of CSS stylesheet describing the styling of a speaker page:
/* file styles.css */
body { font-family: Arial, sans-serif; background-color: #f0f0f0; }
h1 { color: #333; }
p { font-size: 18px; }
#increase-btn { background-color: #4CAF50; color: white; padding: 10px 20px; border: none; cursor: pointer; }
#increase-btn:hover { background-color: #45a049; }
JavaScript (JS): application/javascript (for scripts) should describe the behaviour of a Web page, with no content or styling information
it may contain instructions to manipulate the content and styling of the page (e.g. by adding, removing, or changing elements, classes, attributes, etc.)
such instructions may be triggered by events occurring after the page has been shown to the user (e.g. button clicks, form submissions, etc.)
such instructions are provided by the server, along with the page, to let the client know how to “animate” the page and make it interactive
example of JavaScript code reloading the page when the “Increase Volume” button is clicked:
// file script.js
document.getElementById('increase-btn').addEventListener('click', function() {
location.reload();
});
Wrap-up: most commonly the HTML pages contains references to the CSS and JS files that describe the styling and behaviour of the page, respectively, and the client is responsible for downloading and interpreting all these resources to render the page correctly:
<html>
<head>
<link rel="stylesheet" type="text/css" href="styles.css"> <!-- reference to CSS stylesheet -->
<script src="script.js"></script> <!-- reference to JavaScript file -->
</head>
<body>
<h1>Speaker 123</h1>
<p>Volume: 75%</p>
<button id="increase-btn">Increase Volume</button>
</body>
</html>
JavaScript Object Notation (JSON): application/json (for data exchange) should describe the content of a resource in a machine-friendly way, with no styling or behaviour information
it may contain structured data representing the state of a resource, or the result of an operation on a resource, etc.
[AJAX] sometimes the JS code may contact the server to get some tiny piece of information in JSON format, rather than the entire HTML page, in order to update the page dynamically without reloading it
other times, the client is not a browser, but some software component that just needs data in machine-friendly format
example of JSON document describing a speaker resource:
{
"id": 123,
"name": "Living Room Speaker",
"volume": 75,
"status": "on"
}
document.getElementById('increase-btn').addEventListener('click', function() {
// Send an AJAX request to the server to increase the volume
fetch('/speakers/123/volume', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ change: '+10%' })
}).then(response => {
if (response.ok) {
// If the request was successful, update the volume displayed on the page
let volumeElement = document.querySelector('p');
let currentVolume = parseInt(volumeElement.textContent.split(': ')[1]);
volumeElement.textContent = `Volume: ${currentVolume + 10}%`;
} else {
alert('Failed to increase volume');
}
});
});
other common formats, conceptually equivalent to JSON, include:
application/xml (for data exchange) a sort of generalization of HTML, with custom tags and no predefined semantics:<speaker>
<id>123</id>
<name>Living Room Speaker</name>
<volume>75</volume>
<status>on</status>
</speaker>
application/x-yaml (for data exchange) a sort of generalization of JSON, with more human-friendly syntax (easier to read and write):id: 123
name: Living Room Speaker
volume: 75
status: on
example.com)/var/www/html) where the static files are storedhttps://example.com/index.html)
/var/www/html/index.html is accessible at https://example.com/index.html)index.php)submit.php)Example of PHP script generating a dynamic page for a speaker resource:
<?php
// index.php
$speaker_id = $_GET['id']; // get speaker ID from query parameter
// query database to get speaker information (this is just a placeholder, actual DB code would be needed)
$speaker_info = getSpeakerInfoFromDatabase($speaker_id);
?>
<!DOCTYPE html>
<html>
<head>
<title>Speaker <?php echo $speaker_info['name']; ?></title>
</head>
<body>
<h1>Speaker <?php echo $speaker_info['name']; ?></h1>
<p>Volume: <?php echo $speaker_info['volume']; ?>%</p>
<form action="update_volume.php" method="POST">
<input type="hidden" name="id" value="<?php echo $speaker_id; ?>">
<input type="number" name="change" value="10"> <!-- change in volume -->
<button type="submit">Increase Volume</button>
</form>
</body>
</html>
update_volume.php would trigger a server-side script that updates the speaker’s volume in the database and then redirects back to index.php to show the updated informationSoftware engineering remarks:
Intuition 1: WS are a sort of distributed objects with an HTTP interface, letting clients send requests to produce remote operations and get remote data, without caring about the underlying implementation
Intuition 2: WS may be useful not only to allow visiting Web pages, but in general to build distributed systems where clients and servers exchange data via request–response interactions over HTTP
Intuition 3: clients may not necessarily be browsers, but also other software components (e.g., mobile apps, backend services, etc.) that need to exchange data and functionality over the Web
Single-page applications (SPAs) are Web applications that load a single HTML page and dynamically update it as the user interacts with the app, without reloading the entire page
On the server-side, the SPA architecture typically involves 3 components:
WS are nowadays often referred to as “APIs”. This is imprecise, as API is a more general concept.
WS have nowadays become the backbone of most distributed systems because:
Web metaphors and mechanisms are simple (to understand and engineer) yet very flexible and general
HTTP is pervasive and highly optimized, so using it for novel projects is often sufficient and convenient
the Web stack is programming-language- and platform-independent, so WS are enablers of interoperability and integration across heterogeneous systems
HTTP is widely supported and usually firewall-friendly, which usually implies less networking issues and better accessibility for clients
WS allow for wrapping pre-existing software so as to:
ReST is an architertural style for hypermedia systems, which imposes the following constraints on the design of WS:
ReSTful [Web] APIs are the set of HTTP requests that a WS (adhering to ReST style) is designed to accept, there including:
the endpoints (i.e., URLs) that identify the resources managed by the WS
Designing the Web API is important, and it is commonly performed before implementing either the client or the server,
Formal languages and tools exist to help designing and documenting Web APIs
Useful references:
/products [whatever precedes the path component of the URL is omitted for brevity, e.g. https://example.com]
GET method to read the list of products
?category=electronics&max_price=100200 OK400 Bad Request (e.g., if query parameters are invalid)POST method to create a new product
201 Created with a Location header pointing to the URL of the newly created product (e.g., https://example.com/products/123)400 Bad Request (e.g., if body format is invalid)/products/{id}
{id} is a path parameter, i.e. a placeholder for the product ID identifying a specific product by its IDGET method to read a specific product by its ID
200 OK404 Not Found (e.g., if no product with the specified ID exists)PUT method to update a specific product (e.g. price, description, quantity available) by its ID
204 No Content if the update was successful (with no body in the response)400 Bad Request (e.g., if body format is invalid)404 Not Found (e.g., if no product with the specified ID exists)DELETE method to delete a specific product by its ID
204 No Content if the deletion was successful (with no body in the response)404 Not Found (e.g., if no product with the specified ID exists)[BAD PRACTICE] put verbs/actions in the URL, which implies resources are not being modelled:
POST /increase_volume [“I want to increase the volume, here is the change I want to apply”]
POST /speakers/123/volume with body object representing the desired change[BAD PRACTICE] use the same endpoint for different resources, and distinguish them by query parameters:
GET /course/view.php?id=79314 (BTW this is how UniBO’s Moodle work, unfortunately…)
GET /courses/{academic_year}/{id_or_name}[BAD PRACTICE] reveal implementation details in the API design, resources names after DB tables
GET /table_users (implies that the server is using a table named “users” in its database)
GET /users (which is more abstract and does not reveal implementation details)[BAD PRACTICE] put actions in URL, and abuse meaning of HTTP methods
GET /delete_user?id=123 (implies that the server is using a GET request to perform a delete operation, which is semantically incorrect and may cause issues with caching and other HTTP features)
DELETE /users/123 (which uses the appropriate HTTP method for the intended action)[BAD PRACTICE] design URLs so that they imply some stateful interactions, which is against the statelessness constraint of ReST
GET /products?page=next (implies that the server is keeping track of the client’s current page and returns the next page of products, which is not stateless and may cause issues with caching and scalability)
GET /products?page=2 (where the client explicitly specifies the page number it wants to retrieve, making the interaction stateless)
[BAD PRACTICE] use query parameters for actions that should be represented as resources
POST /users?id=123&action=deactivate (implies that the server is using query parameters to specify an action on a resource, which is not RESTful and may lead to confusion and maintenance issues)
DELETE /users/123 (i.e. deactivating means deleting the user resource, which is more RESTful and semantically correct)PUT /users/123 + body contains information about the deactivation (e.g., {"active": false}, i.e. deactivating means updating the user resource, which is also RESTful and semantically correct)[BAD PRACTICE] use non-standard status codes or ignore them altogether, returning 200 OK for all responses
201 Created for successful resource creation, 400 Bad Request for invalid input, 404 Not Found for non-existent resources, etc.) to provide meaningful feedback to clients and leverage HTTP features effectivelyMost commonly, Web APIs are designed by service providers, documented, and publicly described on the Web so that developers may use them to build custom clients
If you’re working on the provider side, remember:
There are many ways to control access to APIs, which are there both for cybersecurity and business reasons
ReST APIs are so much “de-facto standards” that many monitoring and analytics tools exist to support developers and providers
https://github.com/unibo-dtm-se/ws-example
https://github.com/unibo-dtm-se/ws-example on web4.0 branch
GET vs POST vs PUT/PATCH vs DELETE?1xx, 2xx, 3xx, 4xx, and 5xx status code classes represent?Accept, Content-Type, Authorization, and Cache-Control headers?Accept and Content-Type cooperate in that process?Compiled on: 2026-05-19 — printable version