--- apiVersion: v1 kind: List items: - apiVersion: v1 kind: ConfigMap metadata: labels: funktion.fabric8.io/kind: Connector provider: fabric8 project: connector-rest version: 1.1.41 group: io.fabric8.funktion.connector name: rest data: deployment.yml: | --- apiVersion: extensions/v1beta1 kind: Deployment metadata: labels: funktion.fabric8.io/kind: Subscription connector: rest spec: replicas: 1 template: metadata: labels: funktion.fabric8.io/kind: Subscription connector: rest spec: containers: - image: funktion/connector-rest:1.1.41 name: connector schema.yml: | --- component: kind: component scheme: rest syntax: rest:method:path:uriTemplate title: REST description: The rest component is used for either hosting REST services (consumer) or calling external REST services (producer). label: core,rest deprecated: false async: false lenientProperties: true javaType: org.apache.camel.component.rest.RestComponent groupId: org.apache.camel artifactId: camel-core version: 2.18.1 componentProperties: componentName: kind: property type: string javaType: java.lang.String deprecated: false secret: false description: The Camel Rest component to use for the REST transport such as restlet spark-rest. If no component has been explicit configured then Camel will lookup if there is a Camel component that integrates with the Rest DSL or if a org.apache.camel.spi.RestConsumerFactory (consumer) or org.apache.camel.spi.RestProducerFactory (producer) is registered in the registry. If either one is found then that is being used. order: 0 apiDoc: kind: property type: string javaType: java.lang.String deprecated: false secret: false description: The swagger api doc resource to use. The resource is loaded from classpath by default and must be in JSon format. order: 1 host: kind: property type: string javaType: java.lang.String deprecated: false secret: false description: Host and port of HTTP service to use (override host in swagger schema) order: 2 properties: method: kind: path group: common label: common required: true type: string javaType: java.lang.String enum: - get - post - put - delete - patch - head - trace - connect - options deprecated: false secret: false description: HTTP method to use. order: 0 path: kind: path group: common label: common required: true type: string javaType: java.lang.String deprecated: false secret: false description: The base path order: 1 uriTemplate: kind: path group: common label: common type: string javaType: java.lang.String deprecated: false secret: false description: The uri template order: 2 componentName: kind: parameter group: common label: common type: string javaType: java.lang.String deprecated: false secret: false description: The Camel Rest component to use for the REST transport such as restlet spark-rest. If no component has been explicit configured then Camel will lookup if there is a Camel component that integrates with the Rest DSL or if a org.apache.camel.spi.RestConsumerFactory is registered in the registry. If either one is found then that is being used. order: 3 consumes: kind: parameter group: common label: common type: string javaType: java.lang.String deprecated: false secret: false description: 'Media type such as: ''text/xml'' or ''application/json'' this REST service accepts. By default we accept all kinds of types.' order: 4 inType: kind: parameter group: common label: common type: string javaType: java.lang.String deprecated: false secret: false description: To declare the incoming POJO binding type as a FQN class name order: 5 outType: kind: parameter group: common label: common type: string javaType: java.lang.String deprecated: false secret: false description: To declare the outgoing POJO binding type as a FQN class name order: 6 produces: kind: parameter group: common label: common type: string javaType: java.lang.String deprecated: false secret: false description: 'Media type such as: ''text/xml'' or ''application/json'' this REST service returns.' order: 7 routeId: kind: parameter group: common label: common type: string javaType: java.lang.String deprecated: false secret: false description: Name of the route this REST services creates order: 8 bridgeErrorHandler: kind: parameter group: consumer label: consumer type: boolean javaType: boolean optionalPrefix: consumer. deprecated: false secret: false defaultValue: false description: Allows for bridging the consumer to the Camel routing Error Handler which mean any exceptions occurred while the consumer is trying to pickup incoming messages or the likes will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions that will be logged at WARN/ERROR level and ignored. order: 9 description: kind: parameter group: consumer label: consumer type: string javaType: java.lang.String deprecated: false secret: false description: Human description to document this REST service order: 10 exceptionHandler: kind: parameter group: consumer (advanced) label: consumer,advanced type: object javaType: org.apache.camel.spi.ExceptionHandler optionalPrefix: consumer. deprecated: false secret: false description: To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this options is not in use. By default the consumer will deal with exceptions that will be logged at WARN/ERROR level and ignored. order: 11 exchangePattern: kind: parameter group: consumer (advanced) label: consumer,advanced type: string javaType: org.apache.camel.ExchangePattern enum: - InOnly - RobustInOnly - InOut - InOptionalOut - OutOnly - RobustOutOnly - OutIn - OutOptionalIn deprecated: false secret: false description: Sets the default exchange pattern when creating an exchange. order: 12 apiDoc: kind: parameter group: producer label: producer type: string javaType: java.lang.String deprecated: false secret: false description: The swagger api doc resource to use. The resource is loaded from classpath by default and must be in JSon format. order: 13 host: kind: parameter group: producer label: producer type: string javaType: java.lang.String deprecated: false secret: false description: Host and port of HTTP service to use (override host in swagger schema) order: 14 queryParameters: kind: parameter group: producer label: producer type: string javaType: java.lang.String multiValue: true deprecated: false secret: false description: Query parameters for the HTTP service to call order: 15 synchronous: kind: parameter group: advanced label: advanced type: boolean javaType: boolean deprecated: false secret: false defaultValue: false description: Sets whether synchronous processing should be strictly used or Camel is allowed to use asynchronous processing (if supported). order: 16 documentation.adoc: |+ [[Rest-RestComponent]] Rest Component ~~~~~~~~~~~~~~ *Available as of Camel 2.14* The rest component allows to define REST endpoints (consumer) using the link:rest-dsl.html[Rest DSL] and plugin to other Camel components as the REST transport. From Camel 2.18 onwards the rest component can also be used as a client (producer) to call REST services. [[Rest-URIformat]] URI format ^^^^^^^^^^ [source,java] -------------------------------------------- rest://method:path[:uriTemplate]?[options] -------------------------------------------- [[Rest-URIOptions]] URI Options ^^^^^^^^^^^ // component options: START The REST component supports 3 options which are listed below. {% raw %} [width="100%",cols="2,1m,7",options="header"] |======================================================================= | Name | Java Type | Description | componentName | String | The Camel Rest component to use for the REST transport such as restlet spark-rest. If no component has been explicit configured then Camel will lookup if there is a Camel component that integrates with the Rest DSL or if a org.apache.camel.spi.RestConsumerFactory (consumer) or org.apache.camel.spi.RestProducerFactory (producer) is registered in the registry. If either one is found then that is being used. | apiDoc | String | The swagger api doc resource to use. The resource is loaded from classpath by default and must be in JSon format. | host | String | Host and port of HTTP service to use (override host in swagger schema) |======================================================================= {% endraw %} // component options: END // endpoint options: START The REST component supports 17 endpoint options which are listed below: {% raw %} [width="100%",cols="2,1,1m,1m,5",options="header"] |======================================================================= | Name | Group | Default | Java Type | Description | method | common | | String | *Required* HTTP method to use. | path | common | | String | *Required* The base path | uriTemplate | common | | String | The uri template | componentName | common | | String | The Camel Rest component to use for the REST transport such as restlet spark-rest. If no component has been explicit configured then Camel will lookup if there is a Camel component that integrates with the Rest DSL or if a org.apache.camel.spi.RestConsumerFactory is registered in the registry. If either one is found then that is being used. | consumes | common | | String | Media type such as: 'text/xml' or 'application/json' this REST service accepts. By default we accept all kinds of types. | inType | common | | String | To declare the incoming POJO binding type as a FQN class name | outType | common | | String | To declare the outgoing POJO binding type as a FQN class name | produces | common | | String | Media type such as: 'text/xml' or 'application/json' this REST service returns. | routeId | common | | String | Name of the route this REST services creates | bridgeErrorHandler | consumer | false | boolean | Allows for bridging the consumer to the Camel routing Error Handler which mean any exceptions occurred while the consumer is trying to pickup incoming messages or the likes will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions that will be logged at WARN/ERROR level and ignored. | description | consumer | | String | Human description to document this REST service | exceptionHandler | consumer (advanced) | | ExceptionHandler | To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this options is not in use. By default the consumer will deal with exceptions that will be logged at WARN/ERROR level and ignored. | exchangePattern | consumer (advanced) | | ExchangePattern | Sets the default exchange pattern when creating an exchange. | apiDoc | producer | | String | The swagger api doc resource to use. The resource is loaded from classpath by default and must be in JSon format. | host | producer | | String | Host and port of HTTP service to use (override host in swagger schema) | queryParameters | producer | | String | Query parameters for the HTTP service to call | synchronous | advanced | false | boolean | Sets whether synchronous processing should be strictly used or Camel is allowed to use asynchronous processing (if supported). |======================================================================= {% endraw %} // endpoint options: END [[Components-Supported]] Supported rest components ^^^^^^^^^^^^^^^^^^^^^^^^^ The following components support rest consumer (link:rest-dsl.html[Rest DSL]): * camel-coap * camel-netty-http * camel-netty4-http * camel-jetty * camel-restlet * camel-servlet * camel-spark-rest * camel-undertow The following components support rest producer: * camel-http * camel-http4 * camel-netty4-http * camel-jetty * camel-restlet * camel-undertow [[Rest-PathanduriTemplatesyntax]] Path and uriTemplate syntax ^^^^^^^^^^^^^^^^^^^^^^^^^^^ The path and uriTemplate option is defined using a REST syntax where you define the REST context path using support for parameters.?? TIP:If no uriTemplate is configured then path option works the same way. It does not matter if you configure only path or if you configure both options. Though configuring both a path and uriTemplate is a more common practice with REST. The following is a Camel route using a a path only [source,java] --------------------------------------- from("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". [source,java] -------------------------------------------- from("rest:get:hello/{me}") .transform().simple("Bye ${header.me}"); -------------------------------------------- The following examples have configured a base path as "hello" and then have two REST services configured using uriTemplates. [source,java] ------------------------------------------------ from("rest:get:hello:/{me}") .transform().simple("Hi ${header.me}"); ?? from("rest:get:hello:/french/{me}") .transform().simple("Bonjour ${header.me}"); ------------------------------------------------ [[Rest-Producer]] Rest producer examples ^^^^^^^^^^^^^^^^^^^^^^ You can use the rest component to call REST services like any other Camel component. For example to call a REST service on using `hello/{me}` you can do [source,java] -------------------------------------------- from("direct:start") .to("rest:get:hello/{me}"); -------------------------------------------- And then the dynamic value `{me}` is mapped to Camel message with the same name. So to call this REST service you can send an empty message body and a header as shown: [source,java] -------------------------------------------- template.sendBodyAndHeader("direct:start", null, "me", "Donald Duck"); -------------------------------------------- The Rest producer needs to know the hostname and port of the REST service, which you can configure using the host option as shown: [source,java] -------------------------------------------- from("direct:start") .to("rest:get:hello/{me}?host=myserver:8080/foo"); -------------------------------------------- Instead of using the host option, you can configure the host on the `restConfiguration` as shown: [source,java] -------------------------------------------- restConfiguration().host("myserver:8080/foo"); from("direct:start") .to("rest:get:hello/{me}"); -------------------------------------------- You can use the `producerComponent` to select which Camel component to use as the HTTP client, for example to use http4 you can do: [source,java] -------------------------------------------- restConfiguration().host("myserver:8080/foo").producerComponent("http4"); from("direct:start") .to("rest:get:hello/{me}"); -------------------------------------------- [[Rest-Producer-Binding]] Rest producer binding ^^^^^^^^^^^^^^^^^^^^^ The REST producer supports binding using JSon or XML like the rest-dsl does. For example to use jetty with json binding mode turned on you can configure this in the rest configuration: [source,java] -------------------------------------------- restConfiguration().component("jetty").host("localhost").port(8080).bindingMode(RestBindingMode.json); from("direct:start") .to("rest:post:user"); -------------------------------------------- Then when calling the REST service using rest producer it will automatic bind any POJOs to json before calling the REST service: [source,java] -------------------------------------------- UserPojo user = new UserPojo(); user.setId(123); user.setName("Donald Duck"); template.sendBody("direct:start", user); -------------------------------------------- In the example above we send a POJO instance `UserPojo` as the message body. And because we have turned on JSon binding in the rest configuration, then the POJO will be marshalled from POJO to JSon before calling the REST service. However if you want to also perform binding for the response message (eg what the REST service send back as response) you would need to configure the `outType` option to specify what is the classname of the POJO to unmarshal from JSon to POJO. For example if the REST service returns a JSon payload that binds to `com.foo.MyResponsePojo` you can configure this as shown: [source,java] -------------------------------------------- restConfiguration().component("jetty").host("localhost").port(8080).bindingMode(RestBindingMode.json); from("direct:start") .to("rest:post:user?outType=com.foo.MyResponsePojo"); -------------------------------------------- IMPORTANT: You must configure `outType` option if you want POJO binding to happen for the response messages received from calling the REST service. [[Rest-Moreexamples]] More examples ^^^^^^^^^^^^^ See??link:rest-dsl.html[Rest DSL]??which offers more examples and how you can use the Rest DSL to define those in a nicer RESTful way. There is a *camel-example-servlet-rest-tomcat* example in the Apache Camel distribution, that demonstrates how to use the link:rest-dsl.html[Rest DSL] with link:servlet.html[SERVLET]??as transport??that can be deployed on Apache Tomcat, or similar web containers. [[Rest-SeeAlso]] See Also ^^^^^^^^ * link:configuring-camel.html[Configuring Camel] * link:component.html[Component] * link:endpoint.html[Endpoint] * link:getting-started.html[Getting Started] * link:rest-dsl.html[Rest DSL] * link:servlet.html[SERVLET]