HTTP Provider for Apache Airflow

6.0.1 · active · verified Sun Apr 05

The Apache Airflow HTTP Provider enables seamless integration with HTTP APIs within Airflow DAGs. It offers operators and hooks to send HTTP requests, handle responses, and poke API endpoints. Released independently from core Airflow, it adheres to Semantic Versioning and is currently at version 6.0.1.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `HttpOperator` to perform a GET request and `HttpSensor` to poll an endpoint until a condition is met. Ensure you configure an Airflow HTTP connection named `http_default` pointing to `httpbin.org` (or your target API) before running.

from __future__ import annotations

import pendulum

from airflow.models.dag import DAG
from airflow.providers.http.operators.http import HttpOperator
from airflow.providers.http.sensors.http import HttpSensor

# NOTE: You need to create an HTTP connection in Airflow UI
# Admin -> Connections -> + New Record
# Conn Id: http_default
# Conn Type: HTTP
# Host: httpbin.org
# For HTTPS, see the 'Configuring HTTPS is counter-intuitive' warning.

with DAG(
    dag_id="http_example_dag",
    start_date=pendulum.datetime(2023, 1, 1, tz="UTC"),
    catchup=False,
    schedule=None,
    tags=["http", "example"],
) as dag:
    # Use HttpOperator to make a GET request
    http_get_task = HttpOperator(
        task_id="http_get_request",
        http_conn_id="http_default",
        method="GET",
        endpoint="get", # This will resolve to httpbin.org/get
        data={"param1": "value1", "param2": "value2"},
        response_check=lambda response: "param1" in response.text,
        log_response=True,
    )

    # Use HttpSensor to wait for a specific response
    http_sensor_task = HttpSensor(
        task_id="http_sensor_check",
        http_conn_id="http_default",
        endpoint="status/200", # This will resolve to httpbin.org/status/200
        response_check=lambda response: response.status_code == 200,
        poke_interval=5,
        timeout=60,
    )

    http_get_task >> http_sensor_task

view raw JSON →