What are the different types of request mappings in Spring Boot?

We have seen how to start with spring boot in earlier. In this blog, we will see the different types of request mappings in Spring Boot.

Following are different types of request mappings in Spring Boot.

We can refer code from here…


@GetMapping

  • @GetMapping annotation is used for mapping HTTP GET requests onto specific handler methods. 
  • GET is the primary mechanism of information retrieval and the focus of almost all performance optimizations.
  • It is a composed annotation, a shortcut for @RequestMapping(method=RequestMethod.GET).
  • Following is an example of Get Mapping.

We can call the API from Postman as shown below


@PostMapping

  • This is used to perform resource-specific processing on the request content.
  • @PostMapping annotation is used for mapping HTTP POST requests onto specific handler methods. 
  • It is a composed annotation which is a shortcut for @RequestMapping(method=RequestMethod.PostMapping).
  • Following is an example of Post Mapping.

We can call post API as shown below.


@PutMapping

  • This is used when we want to replace all current representations of the target resource with the requested content.
  • @PutMapping annotation is used for mapping HTTP PUT requests onto specific handler methods. 
  • It is a composed annotation which is a shortcut for @RequestMapping(method=RequestMethod.PutMapping).
  • Following is an example of Put Mapping.

We can call put API as shown below.


@DeleteMapping

  • This is used when we want to replace all current representations of the target resource with the requested content.
  • @DeleteMapping annotation is used for mapping HTTP DELETE requests onto specific handler methods. 
  • It is a composed annotation which is a shortcut for @RequestMapping(method=RequestMethod.DeleteMapping).
  • Following is an example of Delete Mapping.

We can call post API as shown below.


@PatchMapping

  • This mapping is used when we are doing partial updates.  
  • The PATCH method affects the resource identified by the Request-URI and may have side effects on other resources; i.e., new resources may be created, or existing ones modified, by applying a PATCH.
  • @PatchMapping annotation is used for mapping HTTP PATCH requests onto specific handler methods. 
  • It is a composed annotation which is a shortcut for @RequestMapping(method=RequestMethod.PatchMapping).
  • Following is an example of Patch Mapping.

We can call post API as shown below.


-A blog by Shwetali Khambe

Related Posts