MVC annotations

Let's have a look in detail about various MVC annotations:

  • The @RestController annotation is a combination of the @Controller annotation and the @ResponseBody annotation. As mentioned previously, with the @ResponseBody annotation, the return value of the API handlers in controllers will be mapped to the required representation based on the Content-Type header in the request.
  • The @RequestMapping annotation and its convenient aliases, including @GetMapping, @PostMapping, @PatchMapping, @PutMapping, and @DeleteMapping, can be used to create URIs of resources.
  • The @ResponseEntity annotation provides the ability to control the HTTP headers and status codes, besides returning the response body.
  • The @RequestParam annotation provides the ability to specify the URI query parameters of an API.
  • The @PathVariable annotation provides the ability to extract the variables in the URI, for example, the user ID in the /users/{userId} path.
  • The @RequestBody annotation provides the ability to map the request body into an object. With a PATCH request, we can apply this annotation to a parameter of the Map<String, Object> type to receive the partial representation of a resource.
  • The Spring HATEOAS project provides an easy way to create REST representations that follow HATEOAS constraints, mainly building the links in the representation.

We will use the annotations described in the preceding points during the implementation of the APIs in our TaskAgile application.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.240.244