November 2017
Intermediate to advanced
420 pages
10h 29m
English
The Response instance can hold metadata, such as the HTTP status code, along with the entity body. The REST resource method can return the Response object to report back on the status of the REST API call to the caller.
For example, the following resource method returns HTTP 404 Not Found (represented by the following Enum constant: Response.Status.NOT_FOUND) if the department entity object is not found in the data store:
@DELETE @Path("departments/{id}") public Response remove(@PathParam("id") Short id) { Department department = entityManager.find(Department.class, id); if(department == null){ //Department to be removed is not found in data store return Response.status(Response.Status.NOT_FOUND).entity ...