Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Writing Your Own REST API | RESTful API
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

Writing Your Own REST API

Well, let’s move on to the most exciting part and write our own REST API. I suggest that while watching the video, you code along in parallel.

Let’s create a simple RESTful API for a bookstore using Spring Boot. We will include all the necessary components: models, repositories, services, controllers, and DTOs (Data Transfer Objects). The API will support creating, reading, updating, and deleting books.

Short Clip From the Video

In our REST API, we defined the model we’ll be working with (Book model), which includes the following fields:

java

Main

copy
123456
public class Book { private String id; private String name; private String author; private String price; }

Note

The id is generated at the repository level, simulating the behavior of a real database where the ID is automatically generated.

We also implemented endpoints for our application, which we will test in the following chapters.

Examples of the endpoints:

  • GET /books — retrieves all books (findAllBooks() method);
  • POST /bookscreates a new book (createBook() method);
  • PUT /books/{id}updates a book with the specified ID (updateBook() method);
  • DELETE /books/{id}deletes a book with the specified ID (deleteBook() method).

Lombok

We used the @Getter, @Setter, and @AllArgsConstructor annotations for our Book model. These are annotations from the Lombok library, which helps reduce boilerplate code.

Instead of writing repetitive code manually, you simply annotate the class or its fields, and Lombok generates the necessary methods at compile-time.

Lombok dependency:

¿Todo estuvo claro?

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