Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.이 콘텐츠는 선택한 언어로 제공되지 않습니다.
Chapter 117. Rest
Rest Component 링크 복사링크가 클립보드에 복사되었습니다!
링크 복사링크가 클립보드에 복사되었습니다!
Available as of Camel 2.14
The rest component allows to define REST endpoints using the Rest DSL and plugin to other Camel components as the REST transport.
URI format 링크 복사링크가 클립보드에 복사되었습니다!
링크 복사링크가 클립보드에 복사되었습니다!
rest://method:path[:uriTemplate]?[options]
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");
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}");
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}");
from("rest:get:hello:/{me}")
.transform().simple("Hi ${header.me}");
from("rest:get:hello:/french/{me}")
.transform().simple("Bonjour ${header.me}");
More examples 링크 복사링크가 클립보드에 복사되었습니다!
링크 복사링크가 클립보드에 복사되었습니다!
See Rest DSL which offers more examples and how you can use the Rest DSL to define those in a nicer RESTful way.