JAX-RS resources are developed by using annotations defined within the JAX-RS specification. This enables fast development time and eliminates the need for excessive deployment descriptor information. The following steps will outline the process for developing a simple JAX-RS Address Book resource.
|
HTTP Method | URI | Input Type(s) | Output Type(s) | Note(s) |
---|---|---|---|---|
GET | /addresses | n/a | text/plain | n/a |
GET | /addresses/{id} | n/a | text/plain | n/a |
Once deployed, the easiest way to test this resource is through a browser. The fact that the resource methods are based on an HTTP GET enables this. If the resource methods were another type of request, like a POST, it would require a client that could submit data to the resource. (Note: an HTML form is capable of handling this)
First try accessing the full list of names available. The URL you use will be different in that the host will be whatever host your web container is running on and the context root will be whatever you specified during your application deployment. For example, if installed the application with a context root of "/rest", then your URL could look like: http://localhost:9080/rest/addresses. The return content should look like the image below.
Now try targeting the second resource method available. The URI for this resource is a slight extension of the previous one. Include one of the available indexes to retrieve that entry from the list. This would be similar to providing a unique identifier to a record in a database that represents the resource you are looking for. The URL for a specific resource would be http://localhost:9080/rest/addresses/2 where the number at the end is the unique identifier. The returned content should match the image below.