Building a RESTful Web Service with Spring
5/5
()
About this ebook
Related to Building a RESTful Web Service with Spring
Related ebooks
Mastering Spring 5.0 Rating: 5 out of 5 stars5/5Getting Started with React Rating: 0 out of 5 stars0 ratingsExpress Web Application Development Rating: 3 out of 5 stars3/5Node.js By Example Rating: 2 out of 5 stars2/5RESTful Java Web Services Interview Questions You'll Most Likely Be Asked: Second Edition Rating: 0 out of 5 stars0 ratingsTest-Driven Java Development Rating: 4 out of 5 stars4/5Spring Boot Cookbook Rating: 0 out of 5 stars0 ratingsSpring Boot 2: How To Get Started and Build a Microservice - Third Edition Rating: 5 out of 5 stars5/5Java 9 Concurrency Cookbook - Second Edition Rating: 0 out of 5 stars0 ratingsSpring Data Rating: 0 out of 5 stars0 ratingsSpring Boot and Single-Page Applications: Securing Your API with a Single-Page Application Frontend - Second Edition Rating: 0 out of 5 stars0 ratingsSpring Essentials Rating: 0 out of 5 stars0 ratingsMastering Unit Testing Using Mockito and JUnit Rating: 0 out of 5 stars0 ratingsJava: Best Practices to Programming Code with Java Rating: 0 out of 5 stars0 ratingsGrokking the Java Interview Rating: 0 out of 5 stars0 ratingsSpring and Spring Boot Interview Questions and Answers. Tech interviewer’s notes Rating: 5 out of 5 stars5/5Testing with JUnit Rating: 0 out of 5 stars0 ratingsJava Coding Problems: Improve your Java Programming skills by solving real-world coding challenges Rating: 0 out of 5 stars0 ratingsSpring MVC Cookbook Rating: 0 out of 5 stars0 ratingsMastering Java EE Development with WildFly Rating: 0 out of 5 stars0 ratingsSpring Boot in Action Rating: 0 out of 5 stars0 ratingsMastering Hibernate Rating: 0 out of 5 stars0 ratingsModern Java in Action: Lambdas, streams, functional and reactive programming Rating: 2 out of 5 stars2/5Java Hibernate Cookbook Rating: 0 out of 5 stars0 ratings
Programming For You
Python: Learn Python in 24 Hours Rating: 4 out of 5 stars4/5Python Programming : How to Code Python Fast In Just 24 Hours With 7 Simple Steps Rating: 4 out of 5 stars4/5SQL: For Beginners: Your Guide To Easily Learn SQL Programming in 7 Days Rating: 5 out of 5 stars5/5Learn to Code. Get a Job. The Ultimate Guide to Learning and Getting Hired as a Developer. Rating: 5 out of 5 stars5/5Grokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5Learn Python in 10 Minutes Rating: 4 out of 5 stars4/5Python: For Beginners A Crash Course Guide To Learn Python in 1 Week Rating: 4 out of 5 stars4/5Coding All-in-One For Dummies Rating: 4 out of 5 stars4/5Grokking Simplicity: Taming complex software with functional thinking Rating: 4 out of 5 stars4/5Python Machine Learning By Example Rating: 4 out of 5 stars4/5Beginning C++ Programming Rating: 3 out of 5 stars3/5Python Data Structures and Algorithms Rating: 5 out of 5 stars5/5Grokking Artificial Intelligence Algorithms Rating: 0 out of 5 stars0 ratingsSQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5Python for Finance Cookbook: Over 50 recipes for applying modern Python libraries to financial data analysis Rating: 0 out of 5 stars0 ratingsMicroservices Architecture Handbook: Non-Programmer's Guide for Building Microservices Rating: 4 out of 5 stars4/5Narrative Design for Indies: Getting Started Rating: 4 out of 5 stars4/5Learn Algorithmic Trading: Build and deploy algorithmic trading systems and strategies using Python and advanced data analysis Rating: 0 out of 5 stars0 ratingsTensorFlow in 1 Day: Make your own Neural Network Rating: 4 out of 5 stars4/5Mastering C# and .NET Framework Rating: 5 out of 5 stars5/5PYTHON: Practical Python Programming For Beginners & Experts With Hands-on Project Rating: 5 out of 5 stars5/5Learn JavaScript in 24 Hours Rating: 3 out of 5 stars3/5How To Become A Data Scientist With ChatGPT: A Beginner's Guide to ChatGPT-Assisted Programming Rating: 4 out of 5 stars4/5Learn NodeJS in 1 Day: Complete Node JS Guide with Examples Rating: 3 out of 5 stars3/5
Reviews for Building a RESTful Web Service with Spring
1 rating0 reviews
Book preview
Building a RESTful Web Service with Spring - Dewailly Ludovic
Table of Contents
Building a RESTful Web Service with Spring
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. A Few Basics
REST principles
Uniform interface
Client-Server
Stateless
Cacheable
Layered system
Code on demand
The Spring Framework and REST
Our RESTful web service
Architecture
Data model
Summary
2. Building RESTful Web Services with Maven and Gradle
Apache Maven
Dependency management in Apache Maven
Gradle
Dependency management in Gradle
The structure of our sample web service
The anatomy of a Service Module
Local versus Remote Service Invocations
Developing RESTful web services
Working with your favorite IDE
Making services executable
Starting services with Maven
Summary
3. The First Endpoint
The Inventory service
REST and the MVC pattern
Request mapping
Path mapping
HTTP method mapping
Request parameter mapping
Running the service
A few words on data representation
Summary
4. Data Representation
The Data-Transfer-Object design pattern
The API response format
The envelope format
Error management
Pagination support
Customizing JSON responses
API evolutions
HATEOAS
Versioning strategies
URI versioning
Representation versioning
Other approaches
Summary
5. CRUD Operations in REST
Mapping CRUD operations to HTTP methods
Creating resources
Quickly testing endpoints
JSON versus form data
Updating resources
The update endpoint
Testing update requests
Deleting resources
Overriding the HTTP method
Summary
6. Performance
HTTP compression
Content negotiation
gzip or deflate?
gzip compression in RESTful web services
Spring Boot
HTTP caching
Cache-Control
Private/Public caching
No caching
ETags
Last-Modified/If-Modified-Since headers
Room availability
An overview of implementation
The REST resource
Adding HTTP caching
Caching with ETags
Summary
7. Dealing with Security
The booking service
The REST resource
Authentication
HTTP Basic authentication
Using Basic authentication with Spring
HTTP Digest authentication
Token-based authentication
Other authentication methods
Authorization
Authorization with Spring
URL mapping
Resource annotations
Input validation
Java Bean annotations
Regular expressions
Validating bookings
Encryption
Storing sensitive data
Summary
8. Testing RESTful Web Services
Unit testing Spring controllers
Mocking
Simple mocking
Implementation stubbing with a mocking library
Mockito and Spring
Testing security
Integration testing
Continuous delivery
Integration tests with Spring Boot
Postman
Postman and security
Other forms of testing
User Acceptance Testing
Load testing
Summary
9. Building a REST Client
The basic setup
Declaring a client
Remote versus local clients
Availability and booking services
Handling security
The Basic authentication
The Digest authentication
HTTP public key pinning
Exception handling
Summary
10. Scaling a RESTful Web Service
Clustering
Scaling up versus scaling out
The benefits of clustered systems
Load balancing
Linear scalability
Distributed caching
Data-tier caching
First-level caching
Second-level caching
Application-tier caching
Asynchronous communication
Summary
Index
Building a RESTful Web Service with Spring
Building a RESTful Web Service with Spring
Copyright © 2015 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: October 2015
Production reference: 1081015
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78528-571-4
www.packtpub.com
Credits
Author
Ludovic Dewailly
Reviewers
Fabricio Silva Epaminondas
Greg L. Turnquist
Commissioning Editor
Pratik Shah
Acquisition Editor
Ruchita Bhansali
Content Development Editor
Nikhil Potdukhe
Technical Editor
Menza Mathew
Copy Editor
Angad Singh
Project Coordinator
Izzat Contractor
Proofreader
Safis Editing
Indexer
Rekha Nair
Production Coordinator
Aparna Bhagat
Cover Work
Aparna Bhagat
About the Author
Ludovic Dewailly is a senior, hands-on software engineer and development manager with over 12 years of experience in designing and building software solutions on platforms ranging from resource-constrained mobile devices to cloud-computing systems. He is currently helping FancyGiving.com (a social shopping, wishing, and gifting platform) design and build their system. Ludovic's interests lie in software architecture and tackling the challenges of web scale.
I would like to thank my fiancée, Gaia, for helping me find the time to work on this book, and for dealing with my testiness after late-night writing sessions. I would also like to thank Neil Emerick from NightsBridge (http://www.nightsbridge.co.za) for providing me with the idea and concepts behind the sample RESTful web service that outlines this book.
Also, I would like to give gratitude to Chris Laffra and Michael Van Meekeren from the defunct Object Technology International, who gave me my first taste of commercial software development.
Finally, I wish to thank Nikhil Potdukhe and Menza Mathew from Packt Publishing for guiding me and helping me convert the original concept of this project into an actual book.
About the Reviewers
Fabricio Silva Epaminondas has a degree in computer science and a solid background in software development, testing, and engineering. He has been an agile and quality enthusiast for more than 10 years with working experience in the field, having held several roles in fields ranging from project management to software architecture and team leadership.
Fabricio has also worked with mobile, web, and cloud technologies for research institutes and big companies in Brazil and other countries. There, he developed fast and scalable software solutions in the segments of e-commerce, enterprise integration, corporate governance, and innovative solutions.
Fabricio is the technical author of the blog, fabricioepa.wordpress.com. You can find out more about his professional profile at br.linkedin.com/in/fabricioepa.
I would like to thank my blessed wife, Buna Suellen, who fully supported me during the production of this book.
Greg L. Turnquist (@gregturn) has developed software professionally since 1997. From 2002-2010, he was the lead developer for Harris's $3.5 billion FAA telecommunications program, architecting mission-critical enterprise apps while managing a software team.
In 2010, he joined the Spring team that is now a key part of the start-up company, Pivotal. As a test-bitten script junky, Spring Pro, and JavaScript padawan, Greg works on the Spring Data team while also running the Nashville JUG.
In 2014, he wrote his most recent technical book, Learning Spring Boot, for Packt Publishing. He is passionate about application development, writing (fiction and non-fiction), and coffee.
You can read his blog at http://blog.GregLTurnquist.com, and also sign up for his newsletter.
www.PacktPub.com
Support files, eBooks, discount offers, and more
For support files and downloads related to your book, please visit www.PacktPub.com.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
https://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.
Why subscribe?
Fully searchable across every book published