Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Building RESTful Web Services with Spring 5

You're reading from   Building RESTful Web Services with Spring 5 Leverage the power of Spring 5.0, Java SE 9, and Spring Boot 2.0

Arrow left icon
Product type Paperback
Published in Jan 2018
Publisher Packt
ISBN-13 9781788475891
Length 228 pages
Edition 2nd Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Ludovic Dewailly Ludovic Dewailly
Author Profile Icon Ludovic Dewailly
Ludovic Dewailly
Raja CSP Raman Raja CSP Raman
Author Profile Icon Raja CSP Raman
Raja CSP Raman
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Preface 1. A Few Basics FREE CHAPTER 2. Building RESTful Web Services in Spring 5 with Maven 3. Flux and Mono (Reactor Support) in Spring 4. CRUD Operations in Spring REST 5. CRUD Operations in Plain REST (Without Reactive) and File Upload 6. Spring Security and JWT (JSON Web Token) 7. Testing RESTful Web Services 8. Performance 9. AOP and Logger Controls 10. Building a REST Client and Error Handling 11. Scaling 12. Microservice Basics 13. Ticket Management – Advanced CRUD 14. Other Books You May Enjoy

REST – a basic understanding

Contrary to popular belief, REST is not a protocol, but an architectural principle for managing state information. It's mainly used in web applications. REST was introduced by Roy Fielding to overcome implementation difficulties in SOAP. Roy's doctoral dissertation made for an easy way to retrieve data, regardless of the platform used. You will see all the components of RESTful web services in the following sections.

Uniform interface

In REST principles, all resources are identified by the Uniform Resource Identifier (URI).

HTTP REST resources are represented in some media types, such as XML, JSON, and RDF. Also, RESTful resources are self-descriptive, which means enough information is given to describe how to process the request.

In another REST principle, the clients interact with servers through hypermedia, which is dynamically provided by the servers. Other than endpoints, clients don't need to know how to interact with RESTful services. This principle is referred to as Hypermedia as the Engine of Application State (HATEOAS).

Client and server

By separating REST entities such as the client and server, we can reduce the complexity of REST principles, which will show clear boundaries between server and client. This decoupling will help developers concentrate on the client and server independently. Also, it will help to manage different roles for the client and server.

Stateless

In REST principles, the server will not keep any state about the client session on the server side; hence, it's stateless. If two calls are made to the server from a single client, the server will not identify whether both the calls are from the same client or not. As far as the server knows, every request is independent and new. Based on the URL, HTTP headers, and request body, including the parameters, the operation might be changed on the server side.

Cacheable

With RESTful web services, a client can cache any response coming from the server. The server can mention how, and for how long, it can cache the responses. With the caching option, a client can use the responses instead of contacting the server again. Also, caching will improve scalability and performance by avoiding client-server interactions all the time.

This principle has significant advantages for scalability. Caching techniques will be discussed in Chapter 8, Performance.

Since REST typically leverages HTTP, it inherits all the caching properties that HTTP offers.

Layered system

By providing the layered system, a server can hide its identity. By doing this, clients won't know which server they are dealing with. This policy gives more security control by providing intermediate servers and supports the load-balancing feature, too. Also, intermediate servers can improve scalability and performance through load-balancing and shared caches.

Code on demand (COD)

Code on demand (COD) is considered an optional principle. Servers can extend the functionality of clients by transferring executable code. For example, JavaScript can be provided to web-based clients to customize the functionality. As code on demand reduces the visibility of the client side, this constraint is optional. Also not all APIs need this feature.

More on REST

In web applications, REST is typically used over HTTP. REST doesn't need to be tied to any specific protocol. In HTTP REST, we mainly use the GET, POST, PUT, and DELETE methods to change the state of the resources we access. Other HTTP methods, such as OPTIONS, HEAD, CONNECT, and TRACE, can be used for more advanced operations, for example, for caching and debugging purposes. Most servers have disabled advanced methods for security and simplicity reasons; however, you can enable them by adjusting the server configuration files. As JSON is used as a primary media type for major applications, we also use only the JSON media type for our web service calls.

You have been reading a chapter from
Building RESTful Web Services with Spring 5 - Second Edition
Published in: Jan 2018
Publisher: Packt
ISBN-13: 9781788475891
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.
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 $19.99/month. Cancel anytime