Skip to content

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} :=

camel.destroyRoute('RestOne')
camel.destroyRoute('RestTwo')
camel.destroyRoute('RestThree')
camel.destroyRoute('RestFour')

Warning

The context path REST endpoints should be defined with a root of /public otherwise the endpoints will be inspected for a valid access-token issued by the Portal.

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:

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)