Writing your first REST service
In the following sections, we are going to create our first REST service. Creating a REST service in JAX-RS requires the following two steps:
- Writing a resource class: A class where we will write our web services methods
- Configuring Jersey for our project: Telling the application server to load Jersey, and referencing the resource class we will be creating
Writing a resource class
A resource class is the primary building block of RESTful services in JAX-RS. It's a POJO that includes one or more resource methods. Each resource method represents a RESTful service that can be called using one of the main core HTTP methods (GET
, POST
, PUT
, or DELETE
).
In order to create a resource class, you will add the @Path
annotation to your POJO. The annotation is passed a relative URI that represents the URL of your RESTful service. You will introduce one or more method, annotated with one of the method designator annotations (@GET
,@POST
,@PUT
, or@DELETE
).
Let's see an example...