| = REST API Component | |
| :doctitle: REST API | |
| :shortname: rest-api | |
| :artifactid: camel-rest | |
| :description: Expose OpenAPI Specification of the REST services defined using Camel REST DSL. | |
| :since: 2.16 | |
| :supportlevel: Stable | |
| :tabs-sync-option: | |
| :component-header: Only consumer is supported | |
| :core: | |
| *Since Camel {since}* | |
| *{component-header}* | |
| The REST API component is used for providing Swagger API of the REST services which has been defined using the rest-dsl in Camel. | |
| // component options: START | |
| include::partial$component-configure-options.adoc[] | |
| include::partial$component-endpoint-options.adoc[] | |
| include::partial$component-endpoint-headers.adoc[] | |
| // component options: END | |
| == Usage | |
| You do not use the `rest-api` endpoint in a route yourself. | |
| The xref:manual::rest-dsl.adoc[Rest DSL] creates a route from it when the REST configuration has an `apiContextPath`. | |
| That route serves the OpenAPI document of the REST services at that path. | |
| It needs the `camel-openapi-java` component on the classpath. | |
| [source,yaml] | |
| ---- | |
| - restConfiguration: | |
| apiContextPath: /api-doc | |
| - rest: | |
| path: /orders | |
| get: | |
| - path: "/{id}" | |
| to: | |
| uri: direct:getOrder | |
| - route: | |
| from: | |
| uri: direct:getOrder | |
| steps: | |
| - setBody: | |
| expression: | |
| simple: | |
| expression: "Order ${header.id}" | |
| ---- | |
| With this, `GET /api-doc` returns the OpenAPI document, which describes `GET /orders/\{id}`. |