Spark ComponentAvailable as of Camel 2.14 The Spark component allows to define REST endpoints using the Spark Java library which has a nice DSL. Maven users will need to add the following dependency to their pom.xml for this component: URI formatURI Options
Path using Spark syntaxThe path option is defined using a Spark syntax where you define the REST context path using support for parameters and splat. See more details at the Spark Route documentation. The following is a Camel route using a fixed path And the following route uses a parameter which is mapped to a Camel header with the key "me". Mapping to Camel MessageThe Spark Request object is mapped to a Camel Message as a org.apache.camel.component.spark.SparkMessage which has access to the raw Spark request using the getRequest method. By default the Spark body is mapped to Camel message body, and any HTTP headers / Spark parameters is mapped to Camel Message headers. There is special support for the Spark splat syntax, which is mapped to the Camel message header with key splat. 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. SparkRouteBuilderIf you use Java code, then you can use the class
When using the SparkRouteBuilder, then you can define Camel routes using the REST verbs, such as get, post, put, delete etc. More examplesThere is a camel-example-spark-tomcat example in the Apache Camel distribution, that demonstrates how to use camel-spark in a web application that can be deployed on Apache Tomcat, or similar web containers. See Also |