Spring REST

Book description

Spring REST is a practical guide for designing and developing RESTful APIs using the Spring Framework. This book walks you through the process of designing and building a REST application while taking a deep dive into design principles and best practices for versioning, security, documentation, error handling, paging, and sorting.

This book provides a brief introduction to REST, HTTP, and web infrastructure. You will learn about several Spring projects such as Spring Boot, Spring MVC, Spring Data JPA, and Spring Security and the role they play in simplifying REST application development. You will learn how to build clients that consume REST services. Finally, you will learn how to use the Spring MVC test framework to unit test and integration test your REST API.

After reading this book, you will come away with all the skills to build sophisticated REST applications using Spring technologies.

Table of contents

  1. Cover
  2. Title
  3. Copyright
  4. Dedication
  5. Contents at a Glance
  6. Contents
  7. About the Authors
  8. About the Techincal reviewer
  9. Acknowledgments
  10. Introduction
  11. Chapter 1: Introduction to REST
    1. What is REST?
    2. Understanding Resources
      1. Identifying Resources
      2. URI Templates
    3. Representation
    4. HTTP Methods
      1. Safety
      2. Idempotency
      3. GET
      4. HEAD
      5. DELETE
      6. PUT
      7. POST
      8. PATCH
    5. HTTP Status Codes
    6. Richardson’s Maturity Model
      1. Level Zero
      2. Level One
      3. Level Two
      4. Level Three
    7. Building a RESTful API
    8. Summary
  12. Chapter 2: Spring Web MVC Primer
    1. Spring Overview
      1. Dependency Injection
      2. Aspect Oriented Programming
    2. Spring Web MVC Overview
      1. Model View Controller Pattern
      2. Spring Web MVC Architecture
      3. Spring Web MVC Components
    3. Summary
  13. Chapter 3: RESTful Spring
    1. Generating a Spring Boot Project
      1. Installing a Build Tool
      2. Generating a Project using start.spring.io
      3. Generating a Project using STS
      4. Generating a Project Using the CLI
    2. Accessing REST Applications
      1. Postman
      2. RESTClient
    3. Summary
  14. Chapter 4: Beginning QuickPoll Application
    1. Introducing QuickPoll
    2. Designing QuickPoll
      1. Resource Identification
      2. Resource Representation
      3. Endpoint Identification
      4. Action Identification
    3. QuickPoll Architecture
    4. Implementing QuickPoll
      1. Domain Implementation
      2. Repository Implementation
      3. Embedded Database
      4. API Implementation
    5. Summary
  15. Chapter 5: Error Handling
    1. QuickPoll Error Handling
    2. Error Responses
    3. Input Field Validation
    4. Externalizing Error Messages
    5. Improving RestExceptionHandler
    6. Summary
  16. Chapter 6: Documenting REST Services
    1. Swagger
    2. Integrating Swagger
    3. Swagger UI
    4. Customizing Swagger
    5. Configuring Controllers
    6. Configuring UI
    7. Summary
  17. Chapter 7: Versioning, Paging, and Sorting
    1. Versioning
      1. Versioning Approaches
      2. Deprecating an API
      3. QuickPoll Versioning
      4. Swagger config
    2. Pagination
      1. Page Number Pagination
      2. Limit Offset Pagination
      3. Cursor-Based Pagination
      4. Time-Based Pagination
      5. Pagination Data
      6. QuickPoll Pagination
      7. Changing Default Page Size
    3. Sorting
      1. Sort Ascending or Sort Descending
      2. QuickPoll Sorting
    4. Summary
  18. Chapter 8: Security
    1. Securing REST Services
      1. Session-based Security
      2. HTTP Basic Authentication
      3. Digest Authentication
      4. Certificate-Based Security
      5. XAuth
      6. OAuth 2.0
    2. Spring Security Overview
    3. Securing QuickPoll
      1. cURL
      2. User Infrastructure Setup
      3. UserDetailsService Implementation
      4. Customizing Spring Security
      5. Securing URI
      6. QuickPoll OAuth 2.0 Provider Implementation
      7. Testing QuickPoll OAuth 2.0 Implementation
    4. Summary
  19. Chapter 9: Clients and Testing
    1. QuickPoll Java Client
    2. RestTemplate
      1. Getting Polls
      2. Creating a Poll
      3. PUT Method
      4. DELETE Method
      5. Handling Pagination
      6. Handling Basic Authentication
      7. Handling OAuth 2
    3. Testing REST Services
      1. Spring Test
      2. Unit Testing REST Controllers
      3. Integration Testing REST Controllers
    4. Summary
  20. Chapter 10: HATEOAS
    1. HATEOAS
    2. JSON Hypermedia Types
      1. JSON Hypermedia Types
      2. HAL
    3. HATEOAS in QuickPoll
    4. Summary
  21. Appendix A: Installing cURL on Windows
  22. Index

Product information

  • Title: Spring REST
  • Author(s): Balaji Varanasi, Sudha Belida
  • Release date: June 2015
  • Publisher(s): Apress
  • ISBN: 9781484208236