Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
How HTTP Works | Backend Development Basics
Spring Boot Backend
course content

Contenido del Curso

Spring Boot Backend

Spring Boot Backend

1. Backend Development Basics
2. Spring Boot Basics
3. RESTful API
4. Working with Databases
5. Testing Backend Applications

How HTTP Works

You might have wondered how your requests are processed and how pages with data are loaded depending on the URL you enter in your browser. The HTTP protocol helps us with this process.

What is meant by a client? In the context of HTTP, a client refers to a program or device that initiates requests to a server to retrieve data or resources. Most commonly, the client is a web browser (such as Chrome, Firefox, or Safari) that you use to access websites.

The server's response can be in various formats. You might receive an HTML page that your browser will display, or you may send and receive information in JSON or XML formats (which we will cover later).

Here’s a real-life example:

Imagine you are ordering food at a restaurant. You (the client) place an order with the waiter (sending a request), and the waiter forwards your order to the kitchen (the server). Then, the kitchen prepares your meal and the waiter brings it back to you (returning a response).

In this example, you are the web browser, the waiter is the HTTP protocol, and the kitchen is the server that processes requests and sends responses.

HTTP Methods

HTTP methods define what actions should be performed on resources on the server. The main methods include:

Note

If an HTTP method has a Body, it means that additional data can be sent within the body of the request.

GET

Used to retrieve data from the server. For example, when you open a web page, your browser sends a GET request to load its content.

Imagine you go to a library and ask the librarian (the server) to find a book (the resource). The librarian goes to the shelf, retrieves the book, and returns it to you.

When you open a web page, your browser sends a GET request to "ask" the server to provide the page, just as you would ask for a book at the library.

POST

Sends data to the server to create a new resource. This method is often used to submit form data, such as registration details or comments.

For example, you submit an application for a passport, and the relevant department creates a new record based on your information.

Similarly, when you submit data through a form on a website (such as registration details), a POST request sends that data to the server to create a new resource.

PUT

Used to update existing resources on the server. This method allows you to modify data on the server based on the provided information.

It is similar to updating an existing document. In the web context, a PUT request is used to replace or update an existing resource on the server. For example, you can update information about your user profile.

DELETE

Used to remove resources from the server. For example, this method can be used to delete a user account or a forum post.

Imagine a company decides to remove an outdated contract from its archive. An employee locates the document and deletes it from the database.

PATCH

Used for partial updates to a resource on the server. Unlike a PUT request, which replaces the entire resource, PATCH is used when you need to change only part of the resource.

For example, if you want to update a user's email address in their profile, you can use a PATCH request to modify just the email field.

HEAD

Used to request only the headers of a resource, without retrieving its content.

In a web context, a HEAD request is used to obtain metadata about a resource. For example, it can be used to check if a page has been modified since the last visit or to verify the existence of a file on the server before downloading it.

Note

All of these methods must be specified in the HTTP request signature, which we will now review.

How Does this Work in Practice?

Request

When you enter a URL (codefinity.com) into the search bar, you expect to receive a page with information in response.

In order for a page to be displayed, your browser (the client) sends a request to the server in the following format:

The server corresponding to the host codefinity.com receives this HTTP request, which it reads and understands what the client wants. In this case, the client wants to retrieve something (a GET request), with a specified language for the response and from the provided URL ( / ).

Response

After receiving the request, the server sends an HTTP response, which also consists of several parts:

And the actual body of the response in the form of HTML is our final page that the browser will display, allowing us to see the homepage of the site.

Note

We will discuss the response status in the following chapters, covering what it means and why it is important!

1. What is HTTP?
2. Which HTTP method is used to send data to the server to create a new resource?

What is HTTP?

Selecciona la respuesta correcta

Which HTTP method is used to send data to the server to create a new resource?

Selecciona la respuesta correcta

¿Todo estuvo claro?

Sección 1. Capítulo 2
We're sorry to hear that something went wrong. What happened?
some-alt