HTTP Trigger

Know the trigger and how to use it.

Erick Rubiales avatar
Written by Erick Rubiales
Updated over a week ago

IMPORTANT: This documentation has been discontinued. Read the updated HTTP Trigger documentation on our new documentation portal.

When a pipeline is configured and published with HTTP Trigger, an HTTP endpoint is automatically created. You can visualize this endpoint after the implantation - all you have to do is click on the pipeline card in the Runtime screen.

With this trigger, you have the flexibility to define different content types not only for the request, but also for the endpoint response.

Take a look at the configuration parameters of the trigger:

  • Methods: configured the HTTP verbs to be supported by the endpoint after the implantation. If no value is informed, the default value will be considered: POST, PUT, GET, PATCH, DELETE and OPTIONS.

  • Request Content Types: determines the content types the endpoint can receive. If the parameter is left in blank, any Content-type is accepted.

  • Response Content Types: content types to be returned by the endpoint when the pipeline processing ends. This parameter can’t be left in blank (the response depends on the treatment with mock + Double Braces).

  • Response Headers: headers to be returned by the endpoint when processing in the pipeline is complete. This parameter cannot be left empty and accepts Double Braces. Special characters should not be used in keys, due to possible failures in proxies and gateways.

  • Add Cross-Origin Resource Sharing (CORS) - CORS Headers: add the CORS headers to be returned by the endpoint when processing in the pipeline is complete. Cross-Origin Resource Sharing (CORS) is a mechanism that lets you tell the browser which origins are allowed to make requests. This parameter defines CORS specifically for the pipeline and its constraints. To configure globally rather than individually on each pipeline see the CORS Global article.


    Important: We used a comma to enter multiple values in a header, but we didn't add a space before or after the comma. Special characters should not be used in keys, due to possible failures in proxies and gateways.


  • Maximum Timeout: maximum time for the pipeline to process information before returning a response (default = 30000, limit = 300000). In milliseconds. If the processing takes longer than the parameter definition, the request is finished and returns status-code 500, but with no body at all.

  • Maximum Request Size: maximum payload size (in MB). The maximum limit of the configurable payload is 5MB. If the payload sent by the endpoint consumer overcomes the limit, a message will be returned informing that the maximum size has been overcome and a status-code 413 with the following message:

{
"message": "Request size limit exceeded"
}

  • External API: if the option is enabled, the API is published in an external gateway.

  • Internal API: if the option is enabled, the API is published in an internal gateway. In that case, the internal IP is accessible through the dedicated VPN or the Pipeline Executor only. The pipeline can have both the External API and the Internal API options enabled simultaneously.

  • mTLS enabled API: if the option is enabled, the API is published to a gateway dedicated to APIs with mTLS enabled by default. In this case, the access host will be different from the others. The pipeline can have both the External API and Internal API options enabled at the same time, but it is recommended to leave them inactive. This parameter does not support API Key and JWT. To use it in your realm, it is necessary to make a request via chat and we will send you the necessary information to install this service.

  • API Key: if the option is enabled, the endpoint can be consumed only if an API key previously configured in the Platform is sent.

  • Token JWT: if the option is enabled, the endpoint can be consumed only if a JWT token previously generated by another endpoint with this capacity is sent. Read the article of the JWT implementation to have more details.

  • Additional API Routes: if the option is enabled, the trigger allows you to configure new routes. See more about this parameter below.

  • Routes: displayed only when the Additional API Routes parameter is enabled. Here you can define the endpoint additional routes.

  • Allow Redelivery Of Messages: if the option is enabled, it allows the message to be resent in case the Pipeline Engine fails. Read the article about the Pipeline Engine to have more details.

Additional API Routes

As previously explained, this option is for the configurations of new endpoint routes.

When deploying a pipeline, an URL is automatically created. However, you can customize the route according to your convenience. It also includes the parameters received through the route.

After the pipelines are deployed, the URLs get the following structure:

ou

  • {realm}: corresponds to realm

  • v{n}: pipeline major version

  • {pipeline-name}: name given to the pipeline

Custom static route

Let’s say you’ve created the product-list pipeline. Considering the comment above, your URL would look like this:

https://test.godigibee.io/pipeline/realm/v1/product-list

Now, see how to configure a static route for this case.

With this applied configurations and the deployed pipeline, you get a new URL:

https://test.godigibee.io/pipeline/realm/v1/products 

Custom route with parameter in the route

Using the same example of the previously configured pipeline, see how to custom the route:

With this applied configurations and the deployed pipeline, you get a new URL:

https://test.godigibee.io/pipeline/realm/v1/products/:id

In this case, the endpoint consumer can send a request containing the id of a product and return information only about it. Example of the request URL:

https://test.godigibee.io/pipeline/realm/v1/products/10156

To use this value sent by the route inside the pipeline, go for the Double Braces syntax:

{{ message.queryAndPath.id }}

Adding Response Headers

As explained earlier, this option is used to configure headers in the endpoint response.

Note: Do not use special characters.

To use this value sent by the route within the pipeline, use the Double Braces syntax:

{{ message.parameter }}

HTTP Trigger in Action

See below how the trigger behaves in a determined situation and what its respective configuration is.

Information query API with XML response

Check how to configure a pipeline with HTTP Trigger to return information from inside the pipeline in XML format and how the response must be handled specifically for this trigger.

First of all, create a new pipeline and configure the trigger. The configuration can be made as follows:

With the configurations above, you set that:

  • the endpoint works with the verb GET only;

  • the request accepts content-type related to the XML only;

  • the response returns content-type related to the XML only.

Besides, you determine that the API is external and doesn’t need a token for the communication.


IMPORTANT: this example work for educational matters only. In some cases, you can’t leave the endpoint open for security reasons.


Now observe how to configure a MOCK in the pipeline so it becomes the data provider the endpoint returns in the end. Add the indicated component, connect it to the trigger and configure it with the following JSON:

{
"data": {
"products": [
{
"name": "Samsung 4k Q60T 55",
"price": 3278.99
},
{
"name": "Samsung galaxy S20 128GB",
"price": 3698.99
}
]
}
}

The next step is to add a component that transforms the previously created JSON into a XML pattern. For that, use JSON To XML Transformer, add it to the canvas and connect it to the JSON Generator that was previously added. Keep the following configuration:

After that, the last step is to set and determine how the response of this information will be made to the consumer. Add a MOCK again, given that its function will be to set the response only. Connect it to the JSON To XML Transformer output.

To configure this MOCK, use the following JSON:

{
"code": 200,
"body": {{ message.data }},
"Content-Type": "text/xml"
}

  • code: HTTP Status Code to be returned by the endpoint after a request is finished

  • body: response message body (Double Braces are being used to repass the information converted in the previous step). This item must necessarily be a string. If the data you want to send is a JSON, use the TOSTRING function.

  • Content-type: content type of the response body. All the types are supported, but must be declared in the Response Content Types field.

When done with all these configurations, you should have a pipeline that looks like the image below:

After the deployment, get the generated url and send a GET-type request. The endpoint must return the status-code 200, as previously shown, and the response body should look like this:

<?xml version='1.0' encoding='UTF-8' standalone='no' ?>
<doc>
<products>
<name>Samsung 4k Q60T 55</name>
<price>3278.99</price>
</products>
<products>
<name>Samsung galaxy S20 128GB</name>
<price>3698.99</price>
</products>
</doc>

Whenever you want to make a request to the created endpoint, the structure of the message the trigger delivers to the pipeline is always the same and follows this pattern:

{

  "body": "<xml>\n\t<id>1</id>\n</xml>\t",
"form": {},
"headers": {
"Host": "pipeline-trigger-http:8100",
"Connection": "keep-alive",
"X-Forwarded-For": "***",
"X-Forwarded-Proto": "http",
"X-Forwarded-Host": "***",
"my-custom-header": "a"
},
"queryAndPath": {
"id": "1"
},
"method": "POST",
"contentType": "application/xml",
"path": "/pipeline/digibee/v1/trigger-http/1"
}

  • body: content to be sent in the request payload to be transformed into a string in this field

  • form: if the form-data is used in the request, the sent data is delivered in this field

  • headers: the headers sent in the request are delivered in this field, but some of them are automatically filled with the tool used to make the request

  • queryAndPath: the query and path parameters provided in the URL are delivered in this field

  • method: HTTP method used in the request to be delivered in this field

  • contentType: when informed in the request, the Content-type value is repassed to the pipeline inside this field

  • path: the path used in the URL in the request is repassed to this field

Did this answer your question?