搜索

此内容没有您所选择的语言版本。

Chapter 134. REST

download PDF

Rest Component

Available as of Camel 2.14
The REST component allows you to define REST endpoints using the section "Defining Services with REST DSL" in "Apache Camel Development Guide" and to plug in other Camel components as the REST transport.

URI format

rest://method:path[:uriTemplate]?[options]

URI Options

Name
Default Value
Description
method
HTTP method which should be one of: get, post, put, patch, delete, head, trace, connect, or options.
path
the base path which support REST syntax. See further below for examples.
uriTemplate
uri template which support REST syntax. See further below for examples.
consumes
media type such as: 'text/xml', or 'application/json' this REST service accepts. By default we accept all kinds of types.
produces
media type such as: 'text/xml', or 'application/json' this REST service returns.

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
  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".
  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.
  from("rest:get:hello:/{me}")
    .transform().simple("Hi ${header.me}");
 
  from("rest:get:hello:/french/{me}")
    .transform().simple("Bonjour ${header.me}");

More examples

See section "Defining Services with REST DSL" in "Apache Camel Development Guide" 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 section "Defining Services with REST DSL" in "Apache Camel Development Guide" with Chapter 146, SERVLETSERVLET as transport that can be deployed on Apache Tomcat, or similar web containers.
Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.