Spark REST and Apache Tomcat example
This example shows how to use Spark REST to define REST endpoints in Camel routes using the Java DSL
The routes are defined in Java code, in the org.apache.camel.example.sparkrest.UserRouteBuilder class.
There is a user REST service that supports the following operations
- view/id - to view a user with the given id
- list - to view all users
- update - to update/create an user
The view and list operations are HTTP GET, and update is using HTTP PUT.
From a web browser you can access the first two services using the following links
From the command shell you can use curl to access the service as shown below:
curl -X GET -H "Accept: application/json" http://localhost:8080/camel-example-spark-rest-tomcat-{version}/user/view/123
curl -X GET -H "Accept: application/json" http://localhost:8080/camel-example-spark-rest-tomcat-{version}/user/list
curl -X PUT -d "{ \"id\": 666, \"name\": \"The devil\"}" -H "Accept: application/json" http://localhost:8080/camel-example-spark-rest-tomcat-{version}/user/update
This assume you installed the example by copying the .war as camel-example-spark-rest-tomcat-VERSION.war
, where VERSION is the Camel version such as 2.14.0, into the webapps directory of Apache Tomcat.
If you hit any problems please let us know on the
Camel Forums
Please help us make Apache Camel better - we appreciate any feedback you may
have. Enjoy!
The Camel riders!