Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The Rest DSL supports Swagger by the camel-swagger module. See more details at  Swagger and the camel-example-servlet-rest-tomcat example from the Apache Camel distribution.

From Camel 2.16 onwards you can define each parameter fine grained with details such as name, description, data type, parameter type and so on, using the <param>. For example to define the id path parameter you can do as shown below:

Code Block
xml
xml
<!-- this is a rest GET to view an user by the given id -->
<get uri="/{id}" outType="org.apache.camel.example.rest.User">
  <description>Find user by id</description>
  <param name="id" type="path" description="The id of the user to get" dataType="int"/>
  <to uri="bean:userService?method=getUser(${header.id})"/>
</get>

And in Java DSL

Code Block
.get("/{id}").description("Find user by id").outType(User.class)
    .param().name("id").type(path).description("The id of the user to get").dataType("int").endParam()
    .to("bean:userService?method=getUser(${header.id})")

The body parameter type requires to use body as well for the name. For example a REST PUT operation to create/update an user could be done as:

Code Block
xml
xml
<!-- this is a rest PUT to create/update an user -->
<put type="org.apache.camel.example.rest.User">
  <description>Updates or create a user</description>
  <param name="body" type="body" description="The user to update or create"/>
  <to uri="bean:userService?method=updateUser"/>
</put>

And in Java DSL

Code Block
.put().description("Updates or create a user").type(User.class)
    .param().name("body").type(body).description("The user to update or create").endParam()
    .to("bean:userService?method=updateUser")

 

For an example see the examples/camel-example-servlet-rest-tomcat of the Apache Camel distribution.

See Also