...
The Spark-rest component allows to define REST endpoints using the Spark REST Java library which has a nice using the Rest DSL.
Info |
| Spark Java requires Java 8 runtime. |
...
Code Block |
from("spark-rest:get:/hello/*/to/*")
.transform().simple("Bye big ${header.splat[1]} from ${header.splat[0]}"); |
SparkRouteBuilder
If you use Java code, then you can use the class org.apache.camel.component.sparkrest.SparkRouteBuilder to define routes using a Spark DSL, as shown below
Rest DSL
Apache Camel provides a new Rest DSL that allow to define the REST services in a nice REST style.
For example we can define a REST hello service in Java DSL as shown below:
Code Block |
return new SparkRouteBuilderRouteBuilder() {
@Override
public void configure() throws Exception {
getrest("/hello/:{me}").get()
.route().transform().simple("Bye ${header.me}");
}
}; |
When using the SparkRouteBuilder, then you can define Camel routes using the REST verbs, such as get, post, put, delete etc.
And the same example in XML DSL would be
Code Block |
|
|
<camelContext xmlns="http://camel.apache.org/schema/spring">
<rest uri="/hello/{me}">
<get>
<route>
<transform>
<simple>Bye ${header.me}</simple>
</transform>
</route>
</get>
</rest>
</camelContext>
|
See more details at the Rest DSL.
More examples
There is a camel-example-spark-rest-tomcat example in the Apache Camel distribution, that demonstrates how to use camel-spark-rest in a web application that can be deployed on Apache Tomcat, or similar web containers.
Include Page |
|
|