Reader small image

You're reading from  Hands-On Full Stack Development with Spring Boot 2.0 and React

Product typeBook
Published inJun 2018
Reading LevelBeginner
PublisherPackt
ISBN-139781789138085
Edition1st Edition
Languages
Right arrow
Author (1)
Juha Hinkula
Juha Hinkula
author image
Juha Hinkula

Juha Hinkula is a software development lecturer at Haaga-Helia University of Applied Sciences in Finland. He received an MSc degree in Computer Science from the University of Helsinki and he has over 17 years of industry experience in software development. Over the past few years, he has focused on modern full stack development. He is also a passionate mobile developer with Android-native technology, and also uses React Native.
Read more about Juha Hinkula

Right arrow

Chapter 3. Creating a RESTful Web Service with Spring Boot

In this chapter, we will first create a RESTful web service using the controller class. After that, we will demonstrate how to use Spring Data REST to create a RESTful web service that also covers all CRUD functionalities automatically. We are using the database application that we created in the previous chapter as a starting point.

In this chapter, we will look into the following:

  • What the RESTful web service is
  • How to create a RESTful web service with Spring Boot
  • How to test the RESTful web service

Technical requirements


The Spring Boot application that has been created in previous chapters is necessary.

Postman, cURL, or another suitable tool for transferring data using various HTTP methods is necessary.

Creating a RESTful web service with Spring Boot


Web services are applications that communicate over the internet using the HTTP protocol. There are many different types of web service architectures, but the main idea across all designs is the same. In this book, we are creating a RESTful web service from what is a really popular design nowadays.

Basics of REST

REST (Representational State Transfer) is an architectural style for creating web services. REST is not standard, but it defines a set of constraints defined by Roy Fielding. The six constraints are the following:

  • Stateless: The server doesn't hold any information about the client state.
  • Client server: The client and server act independently. The server does not send any information without a request from the client.
  • Cacheable: Many clients often request the same resources, therefore it is useful to cache responses in order to improve performance.
  • Uniform interface: Requests from different clients look the same. Clients may be, for example...

Summary


In this chapter, we created a RESTful web service with Spring Boot. First, we created a controller and one method that returns all cars in JSON format. Next, we used Spring Data REST to get a fully functional web service with all CRUD functionalities. We covered different types of requests that are needed to use CRUD functionalities of the service that we created. Finally, we also included our queries to service. In the next chapter we will secure our backend using Spring Security.

Questions


  1. What is REST?
  2. How can you create a RESTful web service with Spring Boot?
  3. How can you fetch items using our RESTful web service?
  4. How can you delete items using our RESTful web service?
  5. How can you add items using our RESTful web service?
  6. How can you update items using our RESTful web service?
  7. How can you use queries with our RESTful web service?
lock icon
The rest of the chapter is locked
You have been reading a chapter from
Hands-On Full Stack Development with Spring Boot 2.0 and React
Published in: Jun 2018Publisher: PacktISBN-13: 9781789138085
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime

Author (1)

author image
Juha Hinkula

Juha Hinkula is a software development lecturer at Haaga-Helia University of Applied Sciences in Finland. He received an MSc degree in Computer Science from the University of Helsinki and he has over 17 years of industry experience in software development. Over the past few years, he has focused on modern full stack development. He is also a passionate mobile developer with Android-native technology, and also uses React Native.
Read more about Juha Hinkula