https://www.youtube.com/watch?v=CTrPvCRnw6E
How to Use HTTP Operator in Apache Airflow | Real API Example (Step-by-Step) | Part 5
jsonplaceholder.typicode.com/todos/1
create connection --
go to --> admin --> add connection -->
yang lainnya biar kan blank, lalu save
Balik ke dag, jalan dag yang telah kita buat tadi ,
dag nya seperti ini :
from airflow.sdk import dag,task
from airflow.providers.http.operators.http import HttpOperator
from datetime import datetime
@dag(
dag_id="dag_with_http_operator",
start_date=datetime(2026,1,1),
catchup=False,
schedule=None,
)
def tutorial_http_operator():
call_api=HttpOperator(
task_id="get_post",
http_conn_id = "http_default",
endpoint="jsonplaceholder.typicode.com/todos/1",
method="GET",
response_filter=lambda response: response.json(),
log_response=True,
)
@task
def process_response(api_response):
print(f"The title of the post is:(api_response['title'])")
process_response(call_api.output)
tutorial_http_operator()









0 Response to "Airflow code -- 3"
Posting Komentar