Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between @Path and @Requestmapping in REST webservice

I am working in REST webservice. I was going through some blogs and there I saw for mapping of URL to a method, they used different annotations. Some places used @RequestMapping and some places used @Path. How does both differ?

like image 336
Rashmi Avatar asked Jul 28 '16 06:07

Rashmi


People also ask

What is the difference between value and path in @RequestMapping?

value method is an alias for path method. This is an alias for path(). For example @RequestMapping("/foo") is equivalent to @RequestMapping(path="/foo"). So both methods are similar in that sense.

What is the difference between @RequestMapping and @PostMapping?

Both do the same job. The difference is that @PostMapping is part of a predefined group of compound annotations that internally use @RequestMapping . These annotations act as shortcuts that serve to simplify the mapping of HTTP methods and to more concisely express the methods of manipulation.

What is the use of @RequestMapping annotation?

annotation. RequestMapping annotation is used to map web requests onto specific handler classes and/or handler methods. @RequestMapping can be applied to the controller class as well as methods.

What is @RequestMapping annotation in Spring boot?

One of the most important annotations in spring is the @RequestMapping Annotation which is used to map HTTP requests to handler methods of MVC and REST controllers. In Spring MVC applications, the DispatcherServlet (Front Controller) is responsible for routing incoming HTTP requests to handler methods of controllers.


1 Answers

It depends on the framework that creates the Web service

@RequestMapping is an annotation used in Spring framework https://spring.io/guides/gs/rest-service/

@Path is an annotation used in frameworks implementing JAX-RS API, such as Jersey https://jersey.java.net/documentation/latest/jaxrs-resources.html#d0e2001

If you want to know which one is better, this topic may help

like image 61
Rocherlee Avatar answered Sep 23 '22 21:09

Rocherlee