Now, let's create the API handler to accept the registration request. The following diagram, Figure 9.8, shows the relationship between RegistrationApiController and its dependencies:
As you can see, the RegistrationApiController class has a field named service of the UserService type, which provides an API, register(RegistrationCommand), for registering users. This service API returns nothing when it succeeds and throws RegistrationException when it fails. In the controller, the register(RegistrationPayload) method is the one that we will need to create. The input of this method is an instance of RegistrationPayload that Spring MVC will create from the request body and validate its data automatically before passing it over. The return value of this method is an instance of ResponseEntity that Spring MVC will use to generate the HTTP response.
Now, let's start the implementation with a unit test.