简体   繁体   中英

Difference between RESTEasy and JAX-RS

What is Resteasy? what is the difference between RESTEasy and JAX-RS? What is the difference between @PathParam and @QueryParam ?

According to its homepage RESTEasy is

... a fully certified and portable implementation of the JAX-RS specification.

So JAX-RS is a specification of how a library for implementing REST APIs in Java should look like and RESTEasy is one implementation of that specification.

This effectively means that any documentation on JAX-RS should apply 1:1 to RESTEasy as well.

Query parameters are extracted from the request URI query parameters, and are specified by using the javax.ws.rs.QueryParam annotation in the method parameter arguments.

Example:

@Path("smooth")
@GET
public Response smooth(
    @DefaultValue("2") @QueryParam("step") int step,
    @QueryParam("minm") boolean hasMin,
    @QueryParam("test") String test
    ) { ... }

URL: http://domain:port/context/XXX/smooth?step=1&minm=true&test=value

URI path parameters are extracted from the request URI, and the parameter names correspond to the URI path template variable names specified in the @Path class-level annotation. URI parameters are specified using the javax.ws.rs.PathParam annotation in the method parameter arguments

Example:

@Path("/{userName}")
public class MyResourceBean {
...
@GET
public String printUserName(@PathParam("userName") String userId) {
    ...
}
}


 URL: http://domain:port/context/XXX/naveen

Here, naveen takes as the userName(Path parameter)

JAX-RS is a set of interfaces and classes without real implementation that belong to javax.ws.rs.* packages (they are part of Java SE 6, by Oracle).

RESTEasy as well as, for example, Jersey or Apache CXF , are open source implementations of that JAX-RS classes.

During compilation you need only JAX-RS. In runtime you need only one of that implementations.

Please also note that JAX-RS is only server side specification and RESTEasy has extended it to bring JAX-RS to the client side through the RESTEasy JAX-RS Client Framework.

Info on param, What is the difference between @PathParam and @QueryParam Some great points here regarding params, When to use @QueryParam vs @PathParam - Gareth's answer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM