From Zero to Service — A Guide on Creating an API using Java Spring Boot

tech.mia
Javarevisited
Published in
5 min readFeb 28, 2021

--

Photo by Mark Tegethoff on Unsplash

In this post, we’ll go through all the steps required to get a Java Spring Boot service up and running. At a pretty high level, Spring Boot is an open-source framework that simplifies tasks such as dependency injection and assists with building APIs.

The Goal

We will be implementing a service that will take care of creating, updating, and retrieving cars from an inventory. In this example, if we follow HTTP and REST standards, we can implement this using two API requests.

  1. For the request to retrieve all cars in the inventory, we will use a method of GET. Its route will be /v1/cars and it will return a list of cars.
  2. For the request to create and update cars, we will use a method of PUT. Its route will be /v1/cars/{carId}, where the {carId} parameter is the car's unique identifier. This request will have as part of its request body the full definition of the car you are going to create or update. For simplicity purposes, a car will only have a make and an id property.

The Project

We will proceed now to create our service. One of the simplest ways to achieve this task is to go to https://start.spring.io. Here you can download an empty project that will come with the right dependencies…

--

--

tech.mia
Javarevisited

Passionate about coding. Engineering software one keystroke at a time… ⌨️