Spring Boot REST API Projects with Code Examples


This guide will help you understand the REST API projects with code examples on Github. We have a number of articles explaining these projects. These code examples will help beginners and experts to learn and gain expertise at developing RESTful Services with Spring Boot.

Courses

25 Videos

Image

Spring Boot REST API Projects - Code Examples on Github

Let’s look at the articles in the following sections

  • Projects Creating Basic REST API
  • Adding Unit and Integration Tests to RESTful Services
  • Securing RESTful Services
  • Basic RESTful Service Features
  • Advanced RESTful Service Features

Projects Creating Basic REST API

We explore couple of options of create RESTful Services with Spring Boot

  • Using Spring Boot Web Starter
  • Using Spring Data REST Starter

Using Spring Boot Web Starter, we have articles with

  • An article focusing on basics of a REST Service
  • A project exposing an end to end CRUD API for an entire Resource. The project uses JPA (Hibernate) to connect to a H2 in memory database.
Title Category URL Github
Creating REST Service with Spring Boot REST API URL Project Code on Github
Introduction to Spring Data Rest - Create RESTful APIs at F1 Speed Spring Data URL Project Code on Github
Creating a CRUD REST API/Service with Spring Boot, JPA and Hibernate REST API URL Project Code on Github

Adding Unit and Integration Tests to RESTful Services

Automation Tests (including Unit and Integration Tests) are a key part of ensuring your services and APIs evolve over a time period.

Let’s consider a StudentController which depends on StudentService.

In the unit test

  • We will mock out the StudentService using Mockito
  • We will use Mock MVC framework to launch only StudentController.

A key part of unit testing is to restrict the scope to a minimum. In this unit test, we want to test only the methods in StudentController.

In the integration test

  • We will launch the complete Spring Boot application using @SpringBootTest
  • We will invoke the service methods using TestRestTemplate
  • We will assert the results using a great JSON assert framework - org.skyscreamer.jsonassert.JSONAssert

A key part of integration testing is testing all the layers in the application.

Title Category URL Github
Unit Testing Rest Services with Spring Boot and JUnit REST API URL Project Code on Github
Writing Integration Tests for Rest Services with Spring Boot REST API URL Project Code on Github
Spring Boot - Unit Testing and Mocking with Mockito and JUnit Spring Boot Unit Testing URL Project Code on Github

Securing RESTful Services

In the article below, we implement basic security for a REST API.

Title Category URL Github
Secure Rest Services and Web Applications with Spring Boot Security Starter Spring Boot Basics URL Project Code on Github

Basic RESTful Service Features

Great REST APIs have

  • Awesome Exception Handling - You would want to return the right response with the exact response status based on the situation.
  • Proper Validation - You would want to validate the right stuff and return a message which helps the consumer understand what failed.
  • Current Documentation - A Consumer need to understand how to use your API. Great documentation makes your consumer and your job easy.

Articles below explore these features in depth.

Title Category URL Github
Spring Boot Exception(Error) Handling for RESTful Services REST API URL Project Code on Github
Implementing Validation for RESTful Services with Spring Boot REST API URL Project Code on Github
Spring Boot and Swagger - Documenting RESTful Services REST API URL Project Code on Github

REST API Advanced Features

At the next level, REST APIs have

  • HATEOAS - HATEOAS stands for “Hypermedia as the engine of application state”. When some details of a resource are requested, you will provide the resource details as well as details of related resources and the possible actions you can perform on the resource. For example, when requesting information about a facebook user, a REST service can return the following
    • user details
    • Links to get his recent posts
    • Links to get his recent comments
    • Links to retrieve his friend’s list.
  • Content Negotiation - Why should JSON be the only data exchange format to be supported? What if your consumer loves (or is stuck with) XML? Content Negotiation helps you support multiple data exchange formats for your RESTful API.
  • Versioning - As your API evolves with your and your consumer needs, you would have the need to have multiple versions of the same Resouce API. How do you handle that?

Articles below explore these features in depth.

Spring Boot - HATEOAS for RESTful Services REST API URL Project Code on Github
Spring Boot and Content Negotiation - XML and JSON Representations REST API URL Project Code on Github
Versioning RESTful Services REST API URL Project Code on Github

Other References

Subscribe to get amazing offers on all our courses.

Find out how in28Minutes reached 100,000 Learners on Udemy in 2 years. The in28minutes Way - Our approach to creating awesome learning experiences.

Related Posts

Spring Boot Tutorials for Beginners

At in28Minutes, we are creating a number of tutorials with videos, articles & courses on Spring Boot for Beginners and Experienced Developers. This resources will help you learn and gain expertise at Spring Boot.

20+ Spring Boot Projects with Code Examples

At in28Minutes, we have created more than 20 projects with code examples on Github. We have 50+ articles explaining these projects. These code examples will you learn and gain expertise at Spring Boot.

Microservices with Spring Boot - Part 5 - Using Eureka Naming Server

Let's learn the basics of microservices and microservices architectures. We will also start looking at a basic implementation of a microservice with Spring Boot. We will create a couple of microservices and get them to talk to each other using Eureka Naming Server and Ribbon for Client Side Load Balancing. In part 5 of this series, we will focus on enabling Eureka Naming Server and have the microservices communicate with it.

Microservices with Spring Boot - Part 4 - Using Ribbon for Load Balancing

Let's learn the basics of microservices and microservices architectures. We will also start looking at a basic implementation of a microservice with Spring Boot. We will create a couple of microservices and get them to talk to each other using Eureka Naming Server and Ribbon for Client Side Load Balancing. In part 4 of this series, we will focus on using Ribbon to do Load Balancing.

Microservices with Spring Boot - Part 3 - Creating Currency Conversion Microservice

Let's learn the basics of microservices and microservices architectures. We will also start looking at a basic implementation of a microservice with Spring Boot. We will create a couple of microservices and get them to talk to each other using Eureka Naming Server and Ribbon for Client Side Load Balancing. In part 3 of this series, we will focus on Creating Currency Conversion Microservice.

Microservices with Spring Boot - Part 2 - Creating Forex Microservice

Let's learn the basics of microservices and microservices architectures. We will also start looking at a basic implementation of a microservice with Spring Boot. We will create a couple of microservices and get them to talk to each other using Eureka Naming Server and Ribbon for Client Side Load Balancing. In part 2 of this series, we will focus on Creating Forex Microservice.

Microservices with Spring Boot - Part 1 - Getting Started

Let's learn the basics of microservices and microservices architectures. We will also start looking at a basic implementation of a microservice with Spring Boot. We will create a couple of microservices and get them to talk to each other using Eureka Naming Server and Ribbon for Client Side Load Balancing. In part 1 of this series, lets get introduced to the concept of microservices and understand how to create great microservices with Spring Boot and Spring Cloud.

Getting Started with Spring Boot - 7 things a beginner should know!

Spring Boot is a tricky framework to understand. In this tutorial for beginnners with Spring Boot, we will look at the basics of Spring Boot and help you understand the important concepts - Architecture, Starter Projects, Auto Configuration and Starter Parent. We will look at the architecture of Spring Boot and explore a variety of resources - tutorials, courses and videos - we created to help you get started with Spring Boot effectively.

Creating a SOAP Web Service with Spring Boot Starter Web Services

Let's learn how to create a SOAP Web Service with Spring Boot Starter Web Services. We will take a Contract First approach by definining an XSD and exposing a WSDL from it.

Versioning RESTful Services

Learn why versioning is needed and how you can version your REST API. We will look at 4 ways of versioning and also compare the different approaches.