Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $9.99/month after trial. Cancel anytime.

Building a RESTful Web Service with Spring
Building a RESTful Web Service with Spring
Building a RESTful Web Service with Spring
Ebook280 pages1 hour

Building a RESTful Web Service with Spring

Rating: 5 out of 5 stars

5/5

()

Read preview

About this ebook

This book is intended for those who want to learn to build RESTful web services with the Spring Framework. To make the best use of the code samples included in the book, you should have a basic knowledge of the Java language.
LanguageEnglish
Release dateOct 14, 2015
ISBN9781785283192
Building a RESTful Web Service with Spring

Related to Building a RESTful Web Service with Spring

Related ebooks

Programming For You

View More

Related articles

Reviews for Building a RESTful Web Service with Spring

Rating: 5 out of 5 stars
5/5

1 rating0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    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 for more details.

    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

    Enjoying the preview?
    Page 1 of 1