liveBook · Manning

Chapter 10: Implementing REST endpoints

What you will learn in chapter 10 of Spring Start Here, Second Edition

The introduction explains why AI-generated REST services need careful review and previews the chapter’s endpoint topics.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The introduction explains why AI-generated REST services need careful review and previews the chapter’s endpoint topics.

Key terms: REST services, shapes of requests and responses, security vulnerabilities

10.1 Using REST services to exchange data between apps

This section explains how REST services connect apps through Spring MVC endpoints and why those calls must be designed with possible failures in mind.

Key terms: REST services, endpoint, client, server, REST endpoint, controller action, HTTP method, path, dispatcher servlet, view resolver

10.2 Implementing REST endpoints

This section shows how to turn a Spring MVC controller action into a REST endpoint and how to call basic endpoints with Postman or cURL.

Key terms: Spring MVC, @Controller, @GetMapping, @ResponseBody, view name, HTTP response, @RestController, code duplication, Postman, cURL

10.3 Managing the HTTP response

Introduces the HTTP response as the backend’s reply to a client request and identifies its three parts.

Key terms: HTTP response, response headers, response body, response status

10.3.1 Sending objects as a response body

This section shows how a REST controller returns objects or collections in an HTTP response body, which Spring formats as JSON by default.

Key terms: controller’s action, HTTP response body, data transfer object (DTO), Country, JSON, response body, List, custom converter, records, immutable data carriers

10.3.2 Setting the response status and headers

This section explains what HTTP response statuses and headers communicate and how a Spring controller can customize them with ResponseEntity.

Key terms: response status, 200 OK, 404 Not Found, 400 Bad Request, 500 Error on server, ResponseEntity, response body, response headers, 202 Accepted

10.3.3 Managing exceptions at the endpoint level

The section shows how to turn endpoint exceptions into informative HTTP responses, move exception handling into REST controller advice, and use a contract-first approach to define REST APIs.

Key terms: ResponseEntity, NotEnoughMoneyException, PaymentDetails, ErrorDetails, 400 Bad Request, REST controller advice, controller action, exception management, @RestControllerAdvice, @ExceptionHandler

10.4 Using a request body to get data from the client

This section explains how a REST endpoint receives client data from an HTTP request body and why request bodies are generally avoided with GET.

Key terms: HTTP request body, REST endpoints, @RequestBody, JSON, parameter type, 400 Bad Request, PaymentDetails, HTTP GET, request body, cacheable

10.5 Questions

This section lists review questions for checking understanding of REST endpoints and points readers to Appendix A for answers.

10.6 Summary

The section summarizes how Spring MVC REST endpoints exchange data, produce HTTP responses, and handle exceptions.

Where this is used later

Concepts explained in this chapter

← Chapter 9: Using the Spring web scopes Chapter 11: Consuming REST endpoints →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.