P6Rest
Platform 6 representational state transfer Consumer are HTTP endpoints that can be defined and dynamically deployed to capture any number of requests.
For more information about the Camel REST DSL: https://camel.apache.org/rest-dsl.html
Example¶
This example demonstrates how several routes can be included in the same event definition script. By adding a P6Rest component to Camel, we extend the standard Camel REST API syntax allowing restful routes to be hosted by Platform 6.
Warning
The id()
of a REST route is defined slightly differently to all other routes.
Template: Dev_BaseRestRoute.groovy
${addRoutes}
:=
rest("/public/say")
.get("/hello")
.to("p6cmb://scripts?platform6.request.action=execute&id=RestHello")
.id("RestOne")
rest("/public/say")
.get("/bye")
.to("direct:bye")
.id("RestTwo")
rest("/public/say")
.post("/tankalert")
.consumes("application/json")
.produces("application/json")
.to("p6cmb://scripts?platform6.request.action=execute&id=RestTank")
.id("RestThree")
from("direct:bye")
.transform()
.constant("Bye World")
.routeId("RestFour")
${destroyRoutes}
:=
p6.camel.destroyRoute('RestOne')
p6.camel.destroyRoute('RestTwo')
p6.camel.destroyRoute('RestThree')
p6.camel.destroyRoute('RestFour')
Warning
The context path REST endpoints defined with a root of /apis/
will be inspected for a valid access-token issued by the Portal otherwise the endpoints will be public.
A Platform 6 service called via this component can return a p6rest.body
variable that will be mapped to the Exchange Message Out body
so enabling any REST response content to be returned:
p6.pipeline.put("body","{ success: true }")
Other response headers used to create a REST response
- Content-Type
- CamelHttpResponseCode
- p6rest.* (any header prefixed will be added without the prefix)
When an authenticated user makes a call to a REST endpoint additional information will be added to the response headers: - platform6.request.user - platform6.request.user.permissions
When the REST endpoint is public, the user information added to the request headers will be: - platform6.request.user=anonymous@amalto.com