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 is an addressable HTTP interface that lets a client access backend data or functionality. Unlike a website that typically returns HTML, a REST API usually responds with data such as JSON or XML. The same API can serve different kinds of clients, including mobile and browser-based applications. section 7.0 section 7.1

In Spring MVC, request-mapping annotations connect HTTP requests to controller methods. A Taco Cloud endpoint, for example, can handle a GET request to fetch recently created tacos. Other annotations handle requests commonly used to create, update, or delete resources; those method-to-operation matches are useful conventions, not perfect rules. 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 this table to choose a Spring MVC annotation for an HTTP method. @RequestMapping is the general-purpose alternative, with the method specified separately. section 7.1

A functional request handler offers another way to define a mapping. A RouterFunction connects a request predicate—a condition a request must match—to a handler function. The predicate can match both an HTTP method and a path. section 12.2

package hello;
 
import static org.springframework.web
                 .reactive.function.server.RequestPredicates.GET;
import static org.springframework.web
                 .reactive.function.server.RouterFunctions.route;
import static org.springframework.web
                 .reactive.function.server.ServerResponse.ok;
import static reactor.core.publisher.Mono.just;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.server.RouterFunction;
 
@Configuration
public class RouterFunctionConfig {
 
  @Bean
  public RouterFunction<?> helloRouterFunction() {
    return route(GET("/hello"),
        request -> ok().body(just("Hello World!"), String.class))
      ;
  }
 
}

This configuration maps GET /hello to a handler. The handler returns HTTP 200 with a Hello World! response body; the value is wrapped in a Mono. Add another mapping with andRoute() when the same router needs to handle another request. section 12.2

Not every Spring route is an HTTP endpoint. An RSocket controller uses @MessageMapping to handle messages on a named route rather than HTTP requests for a path. section 14.2.1

How Spring in Action, Sixth Edition covers it

How deep it goes
Explains HTTP mapping annotations and works through a functional request predicate, handler, and response.
Examples
Uses recently created tacos and a GET /hello handler returning a greeting.
What it assumes
Assumes familiarity with @GetMapping and @PostMapping while introducing additional request-handling annotations.
What you can do after
Apply it via Spring MVC annotations or Spring functional routing to map HTTP requests to handlers.
How it connects
Connects REST endpoints to HTTP methods, CRUD, Spring MVC, and functional request routing.

Also explained in

Compare how 27 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.