A CRUD API with Java & Spring Boot

Kelly Hills
Strategio
Published in
3 min readNov 7, 2022

I’m excited to share an overview of one of my favorite software development projects. This project is among my favorites because it helped me understand a bunch of backend engineering concepts. To be specific, it solidified my understanding of APIs, HTTP requests, and the Spring framework.

Image Source

Concepts

In this project, the API allows HTTP requests to be sent via URL to perform actions on data in a database. These actions include creating a new product, reading the current products in the catalog, updating a product with changes, and deleting a product from the catalog.

API — An Application Programming Interface (API) is a tool which software components use to communicate with each other. In the context of this project, a client can send a request to the API. The request will be handled by the API to perform the appropriate action on data in a database.

HTTP — HyperText Transport Protocol (HTTP) is a protocol for retreiving resources through the internet. The four common HTTP request types are GET, POST, PUT, and DELETE. GET requests are used for reading data, POST requests can be used to create new data, PUT requests can update data, and DELETE requests delete data.

URL Also known as a web address, a Uniform Resource Locator (URL) is a unique identifier that is used to locate a resource through the internet. HTTP requests can be sent through URLs.

CRUD — CRUD is an acronym that stands for Create, Read, Update, and Delete. This is a term used to describe four basic actions which can be performed on data through an HTTP request: creating, reading, updating, and deleting data.

The Code

The core of the program is the controller class. The controller class contains the following code for handling the HTTP requests. The annotations (ex. @GetMapping()) are used in Spring Boot to determine which method will be executed for a given URL.

The code for the project can be found in my GitHub Repository.

Demonstration

For this project, I created a MySQL database schema called ‘product_catalog’ which contained a table called ‘products,’ and manually entered one row of data.

Postman is a great tool for testing APIs. With Postman, a URL can be sent to the API. Here, I sent a GET request in a URL. The data which I manually created in the database is then sent as one row in JSON format.

GET request #1

Afterwards, I sent a POST request containing important data in the message body. This data is crucial because it is used to populate a new row in the database.

POST request

The following is a second GET request which displays both the original data and the data which was created in the POST request. Success!

GET request #2

Thank you for reading! Let me know of any feedback you may have! 💭

--

--

Kelly Hills
Strategio

Hi! I’m Kelly, and I’m passionate about using technology to solve practical problems.