0
0
Apache Airflowdevops~20 mins

SimpleHttpOperator for API calls in Apache Airflow - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
SimpleHttpOperator Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this Airflow task log snippet?
Given this SimpleHttpOperator task in Airflow, what will the log show after a successful GET request?
Apache Airflow
from airflow import DAG
from airflow.providers.http.operators.http import SimpleHttpOperator
from datetime import datetime

with DAG('test_dag', start_date=datetime(2023,1,1), schedule_interval='@once') as dag:
    task = SimpleHttpOperator(
        task_id='get_ip',
        method='GET',
        http_conn_id='httpbin_default',
        endpoint='ip'
    )

# Assume httpbin_default points to https://httpbin.org
# The endpoint /ip returns JSON with your IP address
AINFO - Response: {"origin": "123.123.123.123"}
BERROR - Connection refused
CINFO - Response: <html>...</html>
DINFO - Response: 404 Not Found
Attempts:
2 left
💡 Hint
The endpoint /ip on httpbin.org returns your IP in JSON format.
Configuration
intermediate
2:00remaining
Which http_conn_id configuration is correct for SimpleHttpOperator?
You want to configure Airflow's connection to call https://api.example.com with token authentication. Which connection setup is correct for http_conn_id?
AConn Type: HTTP, Host: https://api.example.com, Extra: {"Authorization": "Bearer TOKEN123"}
BConn Type: HTTP, Host: api.example.com, Extra: {"Authorization": "Bearer TOKEN123"}
CConn Type: FTP, Host: https://api.example.com, Extra: {"Authorization": "Bearer TOKEN123"}
DConn Type: HTTP, Host: https://api.example.com, Extra: {"auth_type": "token", "token": "TOKEN123"}
Attempts:
2 left
💡 Hint
The Host should not include the protocol (https://).
🔀 Workflow
advanced
2:00remaining
What happens if SimpleHttpOperator receives a 500 HTTP response?
In an Airflow DAG, a SimpleHttpOperator task calls an API endpoint that returns HTTP 500 error. What is the expected behavior?
AThe task succeeds but logs the 500 error as a warning.
BThe task crashes Airflow scheduler.
CThe task ignores the error and continues to downstream tasks.
DThe task fails and Airflow retries it if retries are configured.
Attempts:
2 left
💡 Hint
HTTP 500 is a server error and SimpleHttpOperator treats non-2xx responses as failures.
Troubleshoot
advanced
2:00remaining
Why does SimpleHttpOperator fail with 'Connection refused' error?
You configured SimpleHttpOperator with http_conn_id pointing to 'my_api'. The task fails with 'Connection refused'. What is the most likely cause?
AThe Airflow scheduler is not running.
BThe HTTP method is not supported by SimpleHttpOperator.
CThe host in 'my_api' connection is incorrect or the server is down.
DThe DAG file has syntax errors.
Attempts:
2 left
💡 Hint
Connection refused means the network connection to the server failed.
Best Practice
expert
3:00remaining
How to securely pass sensitive API tokens to SimpleHttpOperator?
You need to call a private API with a token using SimpleHttpOperator. What is the best practice to handle the token securely?
AStore the token in Airflow Connections Extra field and reference http_conn_id in the operator.
BHardcode the token directly in the DAG Python file in the operator's headers.
CPass the token as a plain text environment variable and read it in the DAG.
DInclude the token in the endpoint URL as a query parameter.
Attempts:
2 left
💡 Hint
Airflow Connections are designed to store credentials securely.