liveBook · Manning

Endpoint

As explained in Spring in Action, Sixth Edition

A REST endpoint is an addressable HTTP interface through which a client accesses a resource or operation according to REST principles.

A REST endpoint lets a client reach backend functionality through an HTTP request. Unlike a conventional website response, which usually contains HTML, a REST API response typically contains data such as JSON or XML. That makes the same backend useful to browser applications, phones, and other clients. section 7.0 section 7.1

In Spring MVC, a controller method becomes an endpoint when a request-handling annotation maps HTTP requests to it. For example, an endpoint can fetch recently created tacos. @GetMapping handles reads, while @PostMapping handles requests that create a resource; Spring MVC also provides mappings for updates and deletes. section 7.1

Table 7.1 Spring MVC’s HTTP request-handling annotations (view table figure)

Annotation

HTTP method

Typical usea

@GetMapping

HTTP GET requests

Reading resource data

@PostMapping

HTTP POST requests

Creating a resource

@PutMapping

HTTP PUT requests

Updating a resource

@PatchMapping

HTTP PATCH requests

Updating a resource

@DeleteMapping

HTTP DELETE requests

Deleting a resource

@RequestMapping

General-purpose request handling; HTTP method specified in the method attribute

 

a Mapping HTTP methods to create, read, update, and delete (CRUD) operations isn’t a perfect match, but in practice, that’s how they’re often used and how you’ll use them in Taco Cloud.

Use the annotation table to choose a mapping for the HTTP method and intended operation. The HTTP-method-to-CRUD correspondence is a practical convention, not a perfect equivalence. section 7.1

A reactive endpoint can instead use a functional route. A RequestPredicate matches a request, and a handler produces a ServerResponse. In the example, route(GET("/hello"), …) matches GET /hello and returns HTTP 200 with “Hello World!” in the body; andRoute adds a separate GET /bye handler. section 12.2

@Bean
public RouterFunction<?> helloRouterFunction() {
  return route(GET("/hello"),
      request -> ok().body(just("Hello World!"), String.class))
      .andRoute(GET("/bye"),
      request -> ok().body(just("See ya!"), String.class))
  ;
}

This listing shows two HTTP endpoints declared together with route and andRoute. section 12.2

Do not confuse an HTTP endpoint with every use of “route.” An RSocket controller maps messages to a named route with @MessageMapping rather than handling HTTP requests at a path. section 14.2.1

How Spring in Action, Sixth Edition covers it

How deep it goes
Explains controller annotations and works through functional request matching and responses; mentions repository-generated endpoints without detailing their setup.
Examples
Uses recently created tacos as a read scenario and GET /hello and GET /bye as functional routes.
What it assumes
Builds on basic HTTP requests and earlier @GetMapping and @PostMapping use, while defining functional routing types as they appear.
What you can do after
Apply it via Spring MVC mapping annotations or reactive RouterFunctions to handle HTTP requests.
How it connects
Connects HTTP methods and CRUD operations to Spring MVC controllers, and request predicates to reactive handlers.

Also explained in

Compare how 26 books explain endpoint →

Related concepts

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