JAX-RS Basics
This sample demonstrates a basic REST-based Web Services using JAX-RS (JSR-311).
Building the sampleÂ
- Open a command line, and navigate to theÂ
<AS_HOME>/samples/Jaxws-Jaxrs\jaxrs_basic
 directory. - Run the relevant command to deploy the web app:
Using Maven
Create a WAR file for the sample using the following command:
mvn clean install
Deploy the generated WAR file on WSO2 AS with the related logs on the console:
mvn -Pdeploy
Using Ant
ant
Start the WSO2 Application Server by executing one of the following commands, whereÂ
<PRODUCT_HOME>
 is the directory where you installed the product distribution:OS Command On Windows <PRODUCT_HOME>\bin\wso2server.bat --run
On Linux/Solaris sh <PRODUCT_HOME>/bin/wso2server.sh
Log in to the management console and click List on the Main menu, under Manage/Applications. This opens the Running Applications page. The deployed applications will be listed here.
- You can open the required web application by clicking the Find Services action.
Running the sample
You can invoke the JAX-RS web application as shown below.
Get the customer instance for customer ID 123 by sending an HTTP GET request to http://localhost:9763/jaxrs_basic/services/customers/customerservice/customers/123. The XML document returns the following:
<Customer> <id>123</id> <name>John</name> </Customer>
Get the product 323 that belongs to order 223 by sending an HTTP GET request to http://localhost:9763/jaxrs_basic/services/customers/customerservice/orders/223/products/323. The XML document returns the following:
<Product> <description>product 323</description> <id>323</id> </Product>
Add the customer named Jack by sending an HTTP POST request to http://localhost:9763/jaxrs_basic/services/customers/customerservice/customers as shown below.
<Customer> <name>Jack</name> </Customer>
Update the customer with ID 123 as shown below by sending an HTTP PUT request to http://localhost:9763/jaxrs_basic/services/customers/customerservice/customers/customers.
<Customer> <id>123</id> <name>John</name> </Customer>
The client code demonstrates how to send HTTP GET/POST/PUT/DELETE requests; whereas, the server code demonstrates how to build a RESTful endpoint through JAX-RS (JSR-311) APIs.