Exposing the REST resources

Now, we have created the repository and service layer, and we are ready to expose our service through HTTP endpoints:

package springfive.twittertracked.domain.resource import org.springframework.web.bind.annotation.*import springfive.twitterconsumer.domain.TrackedHashTagimport springfive.twitterconsumer.domain.service.TrackedHashTagService @RestController@RequestMapping("/api/tracked-hash-tag")class TrackedHashTagResource(private val service:TrackedHashTagService) {   @GetMapping  fun all() = this.service.all()   @PostMapping  fun save(@RequestBody hashTag:TrackedHashTag) = this.service.save(hashTag)}

The code is pretty concise and simple. Take a look at how concise this piece of code is. The preceding code is an example ...

Get Spring 5.0 By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.