Handling HTTP methods
As mentioned earlier, each HTTP request uses a request method, which in most cases is one of GET
, POST
, PUT
, and DELETE
. In RESTful architectures, those HTTP methods are usually used to perform actions based on the following convention:
GET
: Request retrieval of an existing resourcePOST
: Request creation of a new resourcePUT
: Request the updating of an existing resource, or create a new one if it does not existDELETE
: Request deletion of an existing resource
In JAX-RS, a corresponding annotation for each HTTP method exists @GET
, @POST
, @PUT
, and @DELETE
. In the Handling JSON section, we will create a complete CRUD example for a RESTful service that performs creation, retrieval, updating, and deletion actions using those methods.
For now, let's try to use each of these methods in a simple example:
@Path("/hello") public class FirstRest { @GET public String testGet() { return "You have issues a get request!"; } @POST public String testPost...