liveBook · Manning

REST

As explained in Spring Start Here, Second Edition

REST is an architectural style for designing networked resources and their interactions through representations and standardized operations.

REST services let applications communicate through endpoints: a client makes an HTTP call, and a server returns data in the response. In Spring, an endpoint is a controller action mapped to an HTTP method and path. Unlike a page-rendering action, it returns data directly without resolving a view. section 10.1

A Spring REST endpoint can handle both sides of the exchange:

  • Return the response body directly with @ResponseBody or use @RestController. Return ResponseEntity when you need to manage the HTTP status or headers. section 10.6
  • Receive client data through request parameters, path variables, or the HTTP request body. section 10.6
  • Handle exceptions in the endpoint action or separate that logic into REST controller advice; handling exceptions in individual actions can duplicate code. section 10.6

REST is used between web clients and servers, mobile apps and backends, and backend services. Keep practical limits in mind: slow requests, large payloads, or too many concurrent calls can cause timeouts or put pressure on an app. section 10.1

Figure 10.2 When implementing REST endpoints, the Spring MVC flow changes. The app no longer needs a view resolver because the client needs the data returned by the controller’s action directly. Once the controller’s action is completed, the dispatcher servlet returns the HTTP response without rendering any view.

The flow diagram shows how Spring MVC returns the controller action’s data without rendering a view. section 10.1

How Spring Start Here, Second Edition covers it

How deep it goes
Explains endpoint mapping, direct responses, request inputs, status and headers, and exception handling.
Examples
Uses web-client, mobile-app, and backend-service communication as endpoint scenarios.
What it assumes
Assumes familiarity with the Spring MVC mechanism used to expose web-app controller actions.
What you can do after
Build Spring REST endpoints that handle request data, return response bodies, and manage status, headers, or exceptions.
How it connects
Ties REST endpoints to HTTP, Spring MVC, controller actions, and web services.

Also explained in

Compare how 30 books explain REST →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring Start Here, Second Edition. The section links point to the parts of the book it draws on.