0
0
Apache Airflowdevops~10 mins

SimpleHttpOperator for API calls in Apache Airflow - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the SimpleHttpOperator from Airflow.

Apache Airflow
from airflow.providers.http.operators.http import [1]
Drag options to blanks, or click blank then click option'
AHttpHook
BHttpOperator
CSimpleHttpOperator
DHttpSensor
Attempts:
3 left
💡 Hint
Common Mistakes
Importing HttpOperator instead of SimpleHttpOperator
Using HttpSensor which is for sensors, not operators
2fill in blank
medium

Complete the code to create a SimpleHttpOperator task that calls the 'get' method.

Apache Airflow
task = SimpleHttpOperator(
    task_id='call_api',
    method='[1]',
    http_conn_id='my_api',
    endpoint='data'
)
Drag options to blanks, or click blank then click option'
Aget
Bpost
Cput
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'post' instead of 'get' when only retrieving data
Using uppercase method names
3fill in blank
hard

Fix the error in the SimpleHttpOperator code by completing the missing parameter for the connection ID.

Apache Airflow
task = SimpleHttpOperator(
    task_id='call_api',
    method='GET',
    [1]='my_api',
    endpoint='data'
)
Drag options to blanks, or click blank then click option'
Aconn_id
Bhttp_conn_id
Cconnection_id
Dapi_conn
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'conn_id' or 'connection_id' which are incorrect parameter names
Using 'api_conn' which is not recognized
4fill in blank
hard

Fill both blanks to create a SimpleHttpOperator that sends JSON data with a POST request.

Apache Airflow
task = SimpleHttpOperator(
    task_id='post_data',
    method='[1]',
    http_conn_id='my_api',
    endpoint='submit',
    data=[2]
)
Drag options to blanks, or click blank then click option'
Apost
B{'key': 'value'}
C{'data': 123}
Dget
Attempts:
3 left
💡 Hint
Common Mistakes
Using GET method when sending data
Passing data as a string instead of a dictionary
5fill in blank
hard

Fill all three blanks to create a SimpleHttpOperator that calls a GET endpoint with headers and extracts the response.

Apache Airflow
task = SimpleHttpOperator(
    task_id='get_with_headers',
    method='[1]',
    http_conn_id='my_api',
    endpoint='info',
    headers=[2],
    response_filter=[3]
)
Drag options to blanks, or click blank then click option'
Aget
B{'Authorization': 'Bearer token123'}
Clambda response: response.json()
Dpost
Attempts:
3 left
💡 Hint
Common Mistakes
Using POST method instead of GET
Passing headers as a string
Not using a lambda to parse JSON response