41.6. path 和 uriTemplate 语法
path 和 uriTemplate 选项使用 REST 语法定义,您可以使用对参数的支持来定义 REST 上下文路径。
注意
如果没有配置 uriTemplate,则 path 选项的工作方式相同。如果您只配置路径,或者配置这两个选项,则这无关紧要。虽然配置 path 和 uriTemplate 是使用 REST 的更常见做法。
以下是仅使用路径的 Camel 路由
from("rest:get:hello")
.transform().constant("Bye World");
from("rest:get:hello")
.transform().constant("Bye World");
以下路由使用参数,该参数使用键为"me"的 Camel 标头。
from("rest:get:hello/{me}")
.transform().simple("Bye ${header.me}");
from("rest:get:hello/{me}")
.transform().simple("Bye ${header.me}");
以下示例已将基本路径配置为"hello",然后使用 uriTemplates 配置两个 REST 服务。
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}");