liveBook · Manning

Restcontroller annotation

@RestController is a Spring annotation that marks a class as a web controller whose handler return values are written directly to HTTP response bodies.

How 3 Manning books explain it

Spring Microservices in Action

A Spring annotation that marks a class as a web controller whose return values are written to the response body.

How it is used
Uses @RestController to expose HTTP endpoints from a Spring Boot microservice.
How deep it goes
Explains class-level response handling and illustrates endpoint mapping with a returned object.
Examples
Shows a licensing controller and a GET endpoint returning a sample License.
What you can do after
Apply it via Spring Boot to declare a REST controller and return a serialized object.

Read how Spring Microservices in Action explains restcontroller annotation →

Spring in Action, Sixth Edition

@RestController is a Spring annotation that marks a controller whose handler methods write response data directly to the HTTP response body by default.

How it is used
Creates Spring MVC REST controllers whose handler results become HTTP response data rather than view-model input.
How deep it goes
Explains discovery and response-body behavior, contrasts alternatives, and demonstrates endpoint mapping without covering framework internals.
Examples
Demonstrates a TacoController serving recent tacos at /api/tacos?recent and returning JSON, with an optional ID lookup.
What you can do after
Apply it via Spring MVC to build controllers that expose repository-backed data directly through REST endpoints.

Read how Spring in Action, Sixth Edition explains restcontroller annotation →

Spring Start Here, Second Edition

The @RestController annotation marks a Spring MVC controller whose actions return response data directly and are treated as REST endpoints.

How it is used
Avoids repeating @ResponseBody when defining Spring MVC controller actions as REST endpoints.
How deep it goes
Defines the annotation as a combination of @Controller and @ResponseBody, without detailing framework internals.
Examples
Uses a HelloController with /hello and /ciao actions returning greeting strings.
What you can do after
Build it from scratch by marking a controller class with @RestController instead of repeating @ResponseBody on its actions.

Read how Spring Start Here, Second Edition explains restcontroller annotation →

Also covered in

Related concepts

Questions about restcontroller annotation

What is restcontroller annotation?

@RestController is a Spring annotation that marks a class as a web controller whose handler return values are written directly to HTTP response bodies.

Which Manning books explain restcontroller annotation?

Spring Microservices in Action, Spring in Action, Sixth Edition and Spring Start Here, Second Edition.

What is the difference between restcontroller annotation and @Controller?

@RestController is a Spring annotation that marks a class as a web controller whose handler return values are written directly to HTTP response bodies. The Spring @Controller annotation marks a class as a Spring-managed component for handling web requests.

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.