...
Code Block |
---|
<camelContext xmlns="http://camel.apache.org/schema/blueprint"> <restConfiguration component="spark-rest" port="9091"/> <rest path="/say"> <get uri="/hello"> <to uri="direct:hello"/> </get> <get uri="/bye"> <to uri="direct:bye"/> </get> </rest> <route> <from uri="direct:hello"/> <transform> <constant>Hello World</constant> </transform> </route> <route> <from uri="direct:bye"/> <transform> <constant>Bye World</constant> </transform> </route> </camelContext> |
REST DSL and HTTP Transport Component
If we do not explicitly configure an HTTP transport component, then the REST DSL will automatically discover which HTTP component to use by checking for components on the classpath. The REST DSL searches for the default names of any HTTP components, it then uses the first one it finds. If there are no HTTP components on the classpath, and we did not explicitly configure an HTTP transport, then the default HTTP component is camel-http
.
Specifying the content type of requests and responses
You can filter the content type of HTTP requests and responses using the consumes()
and produces()
options in Java, or the consumes
and produces
attributes in XML. The most common content types (officially known as Internet media types) are the following:
text/plain
text/html
text/xml
application/json
application/xml
The content type is specified as an option on a verb clause in the REST DSL:
Code Block |
---|
rest("/email")
.post("/to/{recipient}").consumes("text/plain").produces("text/html").to("direct:foo"); |
In XML, you can set the consumes
and produces
attributes, as follows:
Code Block |
---|
<rest path="/email">
<post uri="/to/{recipient}" consumes="text/plain" produces="text/html">
<to "direct:foo"/>
</get>
</rest> |