user6454491 user6454491 - 1 year ago 80
Java Question

What exactly are JAX-RS/REST resources?

"Resources are one of the fundamental concepts in REST. REST emphasizes the manipulation of resources rather than issuing function calls. Resources have unique identifiers. In HTTP terms, this means associating every resource with at least one URL.",+HTTP+Methods,+and+Paths

What do we implement as a resource? Is it a group of functionalities, an object, multiple objects..?

Answer Source

See Section 3 of the JAXRS Specification :

Using JAX-RS a Web resource is implemented as a resource class and requests are handled by resource methods.

A resource class is a Java class that uses JAX-RS annotations to implement a corresponding Web resource. Resource classes are POJOs that have at least one method annotated with @Path or a request method designator.

So basically it is a class, usually with @Path annotation,

public class HelloWorldResource {

Resource methods are methods of a resource class annotated with a request method designator.

And Resource method is a method, usually annotated with @GET, or @POST, or other:

public String getHello() {
   return "Hello";

A request method designator is a runtime annotation that is annotated with the @HttpMethod annotation. JAX-RS defines a set of request method designators for the common HTTP methods: @GET, @POST, @PUT, @DELETE, @HEAD and @OPTIONS. Users may define their own custom request method designators including alternate designators for the common HTTP methods.

For more details, see jersey documentation about resources.