http

Calls external endpoint.

{% http url:endpoint, method:"GET" as response %}

Accepts:

  • url - endpoint to call

  • method - HTTP method

  • headers - headers of a request

  • body - body of a request

Result is saved in a variable that follows as keyword.

Result has following format:

{
    "status": 200,
    "body": {
        "foo": "bar"
    },
    "headers": {}
    
}

Below code sends a POST request to https://datajet-apps.com

{% assign endpoint = "https://datajet-apps.com" %}

{% json request_body %}
{
  "foo": "bar"
}
{% endjson %}

{% http url:endpoint, method:"POST", body:request_body as response %}

{% if response.status == 200 %}
  {{ response.body | log }}
{% else %}
  {% capture log_row %} Error when accessing {{endpoint}} {% endcapture %}
  {% log log_row %}
{% endif %}

Last updated