Book Image

Building RESTful Web Services with Spring 5 - Second Edition

By : Raja CSP Raman, Ludovic Dewailly
Book Image

Building RESTful Web Services with Spring 5 - Second Edition

By: Raja CSP Raman, Ludovic Dewailly

Overview of this book

REST is an architectural style that tackles the challenges of building scalable web services. In today's connected world, APIs have taken a central role on the web. APIs provide the fabric through which systems interact, and REST has become synonymous with APIs.The depth, breadth, and ease of use of Spring makes it one of the most attractive frameworks in the Java ecosystem. Marrying the two technologies is therefore a very natural choice.This book takes you through the design of RESTful web services and leverages the Spring Framework to implement these services. Starting from the basics of the philosophy behind REST, you'll go through the steps of designing and implementing an enterprise-grade RESTful web service. Taking a practical approach, each chapter provides code samples that you can apply to your own circumstances.This second edition brings forth the power of the latest Spring 5.0 release, working with MVC built-in as well as the front end framework. It then goes beyond the use of Spring to explores approaches to tackle resilience, security, and scalability concerns. Improve performance of your applications with the new HTTP 2.0 standards. You'll learn techniques to deal with security in Spring and discover how to implement unit and integration test strategies.Finally, the book ends by walking you through building a Java client for your RESTful web service, along with some scaling techniques using the new Spring Reactive libraries.
Table of Contents (21 chapters)
Title Page
Copyright and Credits
Dedication
Packt Upsell
Contributors
Preface
6
Spring Security and JWT (JSON Web Token)
Index

Index

A

  • admin login
    • creating / Admin login
  • admin ticket management
    • about / Admin Ticket management
    • ticket view access, providing to admin / Allowing a admin to view all tickets
  • Aerospike
    • reference / Aerospike
  • AOP (@Before) execution
    • about / AOP (@Before) with execution
    • testing / Testing AOP @Before execution
  • AOP (@Before) with annotation
    • about / AOP (@Before) with annotation
    • testing / Testing AOP @Before annotation
  • Apache Maven
    • about / Apache Maven
    • reference / Apache Maven
    • used, for creating project / Creating a project with Maven
  • application-tier caching
    • about / Application-tier caching
    • Memcached / Memcached
    • Redis / Redis
    • Hazelcast / Hazelcast
    • Ehcache / Ehcache
    • Riak / Riak
    • Aerospike / Aerospike
    • Infinispan / Infinispan
    • Cache2k / Cache2k
  • aspect-oriented programming (AOP)
    • about / Aspect-oriented programming (AOP)
    • AOP (@Before) execution / AOP (@Before) with execution
    • AOP (@Before) with annotation / AOP (@Before) with annotation
    • integrating, with JWT / Integrating AOP with JWT

C

  • Cache2k
    • reference / Cache2k
  • cache implementation
    • about / Cache implementation
    • REST resource, using / The REST resource
    • ETags, using / Caching with ETags
  • cache validation
    • about / Cache validation
    • ETags / ETags
    • Last-Modified/If-Modified-Since headers / Last-Modified/If-Modified-Since headers
  • clustering
    • about / Clustering
    • scaling up (vertical scaling) / Clustering
    • scaling out (horizontal scaling) / Clustering
    • benefits / Benefits of clustering
  • content negotiation
    • about / Content negotiation
    • Accept-Encoding / Accept-Encoding
    • Content-Encoding / Content-Encoding
    • server-driven content negotiation / Server-driven content negotiation
    • agent-driven content negotiation / Agent-driven content negotiation
  • createUser
    • implementation, in handler and repository / createUser – implementation in the handler and repository
    • endpoint, testing / Testing the endpoint – createUser
  • CRUD operations
    • HTTP methods / HTTP methods
    • Reactive server initialization / Reactive server initialization
    • sample values, in repository / Sample values in the repository
    • getAllUsers / getAllUsers – mapping
    • getUser / getUser – implementation in the handler and repository
    • createUser / createUser – implementation in the handler and repository
    • updateUser / updateUser – implementation in the handler and repository
    • deleteUser / deleteUser – implementation in the handler and repository, Testing the endpoint – deleteUser
    • mapping, to HTTP methods / Mapping CRUD operations to HTTP methods
    • in Spring 5 / CRUD operation in Spring 5 (without Reactive)
    • getAllUsers implementation / getAllUsers – implementation
    • getUser implementation / getUser – implementation
    • createUser implementation / createUser – implementation
    • updateUser implementation / updateUser – implementation
    • deleteUser implementation / deleteUser – implementation
    • used, for ticket management / Ticket management using CRUD operations
  • CSR login / CSR login
  • CSR ticket management
    • about / CSR Ticket management
    • ticket updation, by CSR / CSR updates a ticket
    • CSRTokenRequired AOP / CSRTokenRequired AOP
    • CSRTokenRequiredAspect / CSRTokenRequiredAspect
    • all tickets, viewing / CSR view all tickets
    • API (ticket controller) / Viewing all tickets by CSR – API (ticket controller), Deleting tickets by CSR – API (ticket controller)
    • single ticket, viewing / CSR view single ticket
    • tickets, deleting / CSR delete tickets
    • service (TicketServivceImpl) / Deleting tickets – service (TicketServivceImpl)
  • customer login
    • creating / Customer login
  • customer service representative (CSR) / Our RESTful web service architecture

D

  • data-tier caching
    • about / Data-tier caching
    • first-level caching / First-level caching
    • second-level caching / Second-level caching
  • database, scaling
    • about / Scaling databases
    • vertical scaling / Vertical scaling
    • horizontal scaling / Horizontal scaling
    • read replicas / Read replicas
    • pool connections / Pool connections
    • multiple masters, using / Use multiple masters
    • load balancing, in DB servers / Load balancing in DB servers
    • database partitioning / Database partitioning
  • database partitioning
    • about / Database partitioning
    • sharding (horizontal partitioning) / Sharding (horizontal partitioning)
    • vertical partitioning / Vertical partitioning
  • deleteUser
    • implementing, in handler and repository / deleteUser – implementation in the handler and repository
    • endpoint, testing / Testing the endpoint – deleteUser
  • dependency trees / Dependency trees
  • distributed caching
    • about / Distributed caching, Other distributed caching
    • data-tier caching / Data-tier caching
    • application-tier caching / Application-tier caching
    • Amazon ElastiCache / Amazon ElastiCache
    • Oracle distributed cache (Coherence) / Oracle distributed cache (Coherence)

E

  • Eclipse MicroProfile / Eclipse MicroProfile
  • Ehcache
    • reference / Ehcache
  • Elastic Load Balancer (ELB) / Netflix Eureka
  • error handling
    • about / Error handling
    • customized exception / Customized exception

F

  • F5
    • reference / Load balancing
  • file uploads
    • REST API / File uploads – REST API
    • testing / Testing the file upload
  • Flux / Flux

G

  • getAllUsers
    • mapping / getAllUsers – mapping
    • implementation, in handler / getAllUsers – implementation in the handler and repository
    • endpoint, testing / Testing the endpoint – getAllUsers
  • getUser
    • implementation, in handler / getUser – implementation in the handler and repository
    • endpoint, testing / Testing the endpoint – getUser

H

  • HAProxy
    • reference / Load balancing
  • HashiCorp Consul / HashiCorp Consul
  • Hazelcast
    • reference / Hazelcast
  • horizontal scaling / Horizontal scaling
  • HTTP cache control
    • public caching / Public caching
    • private caching / Private caching
    • no-cache / No-cache
    • only-if-cached / Only-if-cached
  • HTTP caching
    • about / HTTP caching
    • cache control / HTTP cache control
    • cache validation / Cache validation
  • HTTP compression
    • about / HTTP compression
    • content negotiation / Content negotiation
  • HTTP methods
    • CRUD operations, mapping to / Mapping CRUD operations to HTTP methods
  • Hypermedia as the Engine of Application State (HATEOAS) / Uniform interface

I

  • imperative programming / Imperative and Reactive programming
  • Infinispan
    • reference / Infinispan

J

  • Java
    • Reactive programming / Reactive programming in Java and Spring 5
  • Java Cryptography Architecture (JCA) / Creating a JWT token
  • Java Util Logging (JUL) / Logback framework
  • JSON Web Token (JWT)
    • about / JSON Web Token (JWT)
    • dependency / JWT dependency
    • AOP, integrating with / Integrating AOP with JWT
  • jsoup
    • about / jsoup
    • user, obtaining / Getting a user – jsoup
    • user, adding / Adding a user – jsoup
    • test cases, executing / Running the test cases
  • JUnit
    • about / JUnit
    • MockMVC / MockMvc
    • Postman / Postman
    • SoapUI / SoapUI
    • jsoup / jsoup
  • JWT token
    • subject, obtaining from / Getting a subject from a JWT token

L

  • load balancing / Load balancing
  • Log4j 2.9.1
    • adding, to POM dependency / Adding Log4j 2.9.1 to POM dependency
  • Logback
    • framework / Logback framework
    • dependency and configuration / Logback dependency and configuration
    • implementation in class / Logback implementation in class
  • logger controls
    • about / Logger controls
    • Logback / SLF4J, Log4J, and Logback
    • SLF4J / SLF4J, Log4J, and Logback
    • Log4J / SLF4J, Log4J, and Logback
  • login
    • about / Login and token management
    • customer login / Customer login
    • admin login / Admin login
    • CSR login / CSR login

M

  • microservice
    • about / Introduction to microservices
    • autonomy / Independence and autonomy
    • resilience and fault tolerance / Resilience and fault tolerance
    • automated environment / Automated environment
    • stateless / Stateless
    • benefits / Benefits of microservices
    • components / Microservice components
    • tools / Microservice tools
  • microservice components
    • configuration server / Configuration server
    • load balancer / Load balancer
    • service discovery / Service discovery
    • circuit breaker / Circuit breaker
    • edge server / Edge server
  • microservice tools
    • about / Netflix Eureka
    • Netflix Zuul / Netflix Zuul
    • Spring Cloud Netflix / Spring Cloud Netflix
    • Netflix Ribbon / Netflix Ribbon
    • Netflix Hystrix / Netflix Hystrix
    • Netflix Turbine / Netflix Turbine
    • HashiCorp Consul / HashiCorp Consul
    • Eclipse MicroProfile / Eclipse MicroProfile
  • MockMVC
    • about / MockMvc
    • single user, testing / Testing a single user
  • Mono / Mono
  • monolithic
    • architecture / Monolithic architecture and its drawbacks
    • drawbacks / Monolithic architecture and its drawbacks

N

  • Netflix Eureka / Netflix Eureka
  • Netflix Hystrix
    • about / Netflix Hystrix
    • circuit breaker fallback mechanism / Netflix Hystrix
  • Netflix Ribbon / Netflix Ribbon
  • Netflix Turbine / Netflix Turbine
  • Netflix Zuul / Netflix Zuul

O

  • Open Source Software (OSS) / Spring Cloud Netflix

P

  • Plain Old Java Object (POJO) / Flux
  • POM dependency
    • Log4j 2.9.1, adding / Adding Log4j 2.9.1 to POM dependency
  • POM file
    • viewing, post to project creation / Viewing a POM file after creating a project
  • Postman
    • about / Testing the endpoint – createUser, Postman
    • users, obtaining / Getting all the users – Postman
    • user, adding / Adding a user – Postman
    • JWT, generating / Generating a JWT – Postman
    • subject, obtaining from token / Getting the subject from the token
  • Project Object Model (POM)
    • file structure / POM file structure
    • dependencies / Understanding POM dependencies

R

  • Reactive Core / Reactive Core and Streams
  • Reactive programming
    • about / Imperative and Reactive programming
    • benefits / Benefits of Reactive programming, Benefits of Reactive programming
    • in Java / Reactive programming in Java and Spring 5
    • in Spring 5 / Reactive programming in Java and Spring 5
    • user class, using with / User class with Reactive – REST
  • Reactive Streams (RS)
    • about / Reactive Streams, Reactive Core and Streams, Mono
    • and back pressures / Back pressures and Reactive Streams
  • Redis
    • reference / Redis
  • registration
    • about / Registration
    • customer registration / Customer registration
    • admin registration / Admin registration
    • CSR registration / CSR registration
  • Representational State Transfer (REST)
    • about / REST – a basic understanding, More on REST
    • uniform interface / Uniform interface
    • client and server / Client and server
    • stateless / Stateless
    • cacheable / Cacheable
    • layered system / Layered system
    • code on demand (COD) / Code on demand (COD)
  • resources
    • creating / Creating resources
  • REST API / Basic REST API
  • REST client
    • building / Building a REST client
    • RestTemplate / RestTemplate
  • RESTful web services
    • architecture / Our RESTful web service architecture
    • developing / Developing RESTful web services
    • project base, creating / Creating a project base
    • favorite IDE, working with / Working with your favorite IDE
  • Riak
    • reference / Riak

S

  • server-sent-event (SSE) / Netflix Turbine
  • Single Sign On (SSO) / JSON Web Token (JWT)
  • single ticket
    • viewing by admin / Allowing admin to view a single ticket
  • SLF4j
    • logging levels / Logging levels
  • SoapUI
    • about / Testing the endpoint – createUser, SoapUI
    • users, obtaining / Getting all the users – SoapUI
    • JWT SoapUI, generating / Generating JWT SoapUI
    • subject, obtaining from token / Getting the subject from the token – SoapUI
  • Spring 5
    • Reactive programming / Reactive programming in Java and Spring 5
  • Spring Boot / Spring Boot
  • Spring Cloud Netflix / Spring Cloud Netflix
  • Spring Initializr
    • reference / Developing RESTful web services, Creating resources
  • Spring REST
    • CRUD operations / CRUD operations in Spring REST 
  • Spring Security
    • about / Spring Security
    • authentication / Authentication and authorization
    • authorization / Authentication and authorization
    • JSON Web Token (JWT) / JSON Web Token (JWT)
    • JWT token, creating / Creating a JWT token
    • token, generating / Generating a token
    • subject, getting from JWT token / Getting a subject from a JWT token
    • subject, getting from token / Getting a subject from a token
  • Spring Tool Suite (STS)
    • reference / Working with your favorite IDE

T

  • throwSecure Hash Algorithm (SHA) / Creating a JWT token
  • ticket
    • updating, TicketServiceImpl class / Updating a ticket – service (TicketServiceImpl)
    • service, deleting in TicketServiceImpl / Deleting a service – service (TicketServiceImpl)
    • deleting / Deleting my ticket – API (ticket controller), Deleting tickets – service (TicketServiceImpl):
    • updating, by admin / Admin updates a ticket, Updating a ticket by admin – service (TicketServiceImpl)
    • deleting, by admin / Allowing admin to delete tickets, Deleting tickets by admin – API (ticket controller):
  • ticket management
    • CRUD operations, using / Ticket management using CRUD operations
    • about / Ticket management
    • ticket POJO / Ticket POJO
    • User Ticket management / User Ticket management
    • tickets, obtaining from counter / Getting my tickets – customer
    • single ticket, viewing / Allowing a user to view their single ticket
    • ticket updation, by ticket / Allowing a customer to update a ticket
    • ticket, deleting / Deleting a ticket
  • Ticket Management System / Our RESTful web service architecture
  • ticket POJO
    • about / Ticket POJO
    • user, obtaining by token / Getting a user by token
  • token
    • management / Login and token management
    • generating / Generating a token

U

  • Uniform Resource Identifier (URI) / Uniform interface
  • universally unique identifier (UUIDs) / Use multiple masters
  • updateUser
    • implementing, in handler and repository / updateUser – implementation in the handler and repository
    • endpoint, testing / Testing the endpoint – updateUser
  • user class
    • using, with Reactive programming / User class with Reactive – REST
  • user POJO / User POJO
  • User Ticket management
    • about / User Ticket management
    • ticket controller / Ticket controller
    • UserTokenRequired interface / The UserTokenRequired interface
    • UserTokenRequiredAspect class / The UserTokenRequiredAspect class
  • user types / User types

V

  • vertical scaling / Vertical scaling
  • view ticket method
    • service (TicketServiceImpl) / Getting all tickets – service (TicketServiceImpl)
    • API (ticket controller) / Getting all tickets – API (ticket controller)
    • AdminTokenRequired interface / The AdminTokenRequired interface
    • AdminTokenRequiredAspect class / The AdminTokenRequiredAspect class

W

  • WebFlux / WebFlux