Consuming incoming data with a reactive POST method
Any website that will serve up employee records must surely have a way to enter new ones, right? So, let’s create a web method that does just that by adding to the ApiController
class we started in the previous section:
@PostMapping("/api/employees") Mono<Employee> add(@RequestBody Mono<Employee> newEmployee) { return newEmployee // .map(employee -> { DATABASE.put(employee.name(), employee); return employee; }); }
This Spring WebFlux controller has the following details:
@PostMapping
: Spring Web’s annotation to mapHTTP POST /api/employees
web calls to this method@RequestBody
: This annotation tells Spring Web to deserialize the incoming HTTP request body into anEmployee
data...