February 2019
Intermediate to advanced
442 pages
11h 46m
English
Let's understand how to make a REST call with Kotlin. We expose the REST API to add users to the system. Basic user details along with role information need to be given. Defining REST controller in Kotlin is similar to Java as follows:
@RestController@RequestMapping("/api")class TaskMgmntRESTController {...}
The TaskMgmntRESTController Kotlin class is defined as a REST controller with @RestController and configures the /api URL pattern with the @RequestMapping annotation. We will write a function that handles the registration of users as follows:
@PostMapping(value = "/register", consumes = [MediaType.APPLICATION_JSON_VALUE])fun registerNewUser(@Valid @RequestBody userRegistrationDto: UserRegistrationDTO, errors: Errors): ...