Since we're on a major migration process of this website, some component documents here are out of sync right now. In the meantime you may want to look at the early version of the new website
https://camel.apache.org/staging/
We would very much like to receive any feedback on the new site, please join the discussion on the Camel user mailing list.
Spark-rest ComponentAvailable as of Camel 2.14 The Spark-rest component allows to define REST endpoints using the Spark REST Java library (not to be mistaken with Apache Spark) using the Rest DSL. This component integrates with Spark REST Java library which is a REST library. This is not related to Apache Spark which is a project about big data. Apache Camel also provides a Camel component (camel-spark) for integrating Camel with Apache Spark. Spark REST Java Library requires Java 8 runtime. Maven users will need to add the following dependency to their pom.xml for this component: <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-spark-rest</artifactId> <version>${camel-version}</version> </dependency> URI formatspark-rest://verb:path?[options] URI Options
Path using Spark syntaxThe path option is defined using a Spark REST syntax where you define the REST context path using support for parameters and splat. See more details at the Spark Java Route documentation. The following is a Camel route using a fixed path from("spark-rest:get:hello") .transform().constant("Bye World"); And the following route uses a parameter which is mapped to a Camel header with the key "me". from("spark-rest:get:hello/:me") .transform().simple("Bye ${header.me}"); Mapping to Camel MessageThe Spark Request object is mapped to a Camel Message as a For example the given route below uses Spark splat (the asterisk sign) in the context path which we can access as a header form the Simple language to construct a response message. from("spark-rest:get:/hello/*/to/*") .transform().simple("Bye big ${header.splat[1]} from ${header.splat[0]}"); Rest DSLApache 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 as shown below: return new RouteBuilder() { @Override public void configure() throws Exception { rest("/hello/{me}").get() .route().transform().simple("Bye ${header.me}"); } }; <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 examplesThere 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. |