Building a RESTful Web Service with Spring
eBook - ePub

Building a RESTful Web Service with Spring

  1. 128 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Building a RESTful Web Service with Spring

Book details
Book preview
Table of contents
Citations

About This Book

A hands-on guide to building an enterprise-grade, scalable RESTful web service using the Spring Framework

About This Book

  • Follow best practices and explore techniques such as clustering and caching to achieve a scalable web service
  • Leverage the Spring Framework to quickly implement RESTful endpoints
  • Learn to implement a client library for a RESTful web service using the Spring Framework

Who This Book Is For

This book is intended for those who want to learn to build RESTful web services with the Spring Framework. To make best use of the code samples included in the book, you should have a basic knowledge of the Java language. Previous experience with the Spring Framework would also help you get up and running quickly.

What You Will Learn

  • Deep dive into the principles behind REST
  • Expose CRUD operations through RESTful endpoints with the Spring Framework
  • Devise response formats and error handling strategies, offering a consistent and flexible structure to simplify integration for service consumers
  • Follow the best approaches for dealing with a service's evolution while maintaining backward compatibility
  • Understand techniques to secure web services
  • Comply with the best ways to test RESTful web services, including tips for load testing
  • Optimise and scale web services using techniques such as caching and clustering

In Detail

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 book goes beyond the use of Spring and explores approaches to tackle resilience, security, and scalability concerns. 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 for it.

Style and approach

This book is a step-by-step, hands-on guide to designing and building RESTful web services. The book follows the natural cycle of developing these services and includes multiple code samples to help you.

Frequently asked questions

Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes, you can access Building a RESTful Web Service with Spring by Ludovic Dewailly in PDF and/or ePUB format, as well as other popular books in Computer Science & Web Services & APIs. We have over one million books available in our catalogue for you to explore.

Information

Year
2015
ISBN
9781785285714
Edition
1

Building a RESTful Web Service with Spring


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

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.

Table of contents

  1. Building a RESTful Web Service with Spring