What is the purpose of the SimpleHttpOperator in Airflow?
SimpleHttpOperator is used to make HTTP requests to APIs or web services as part of an Airflow workflow.
Click to reveal answer
beginner
Which HTTP methods can SimpleHttpOperator use?
SimpleHttpOperator supports common HTTP methods like GET, POST, PUT, DELETE, and PATCH.
Click to reveal answer
beginner
How do you specify the API endpoint URL in SimpleHttpOperator?
You specify the endpoint URL using the 'endpoint' parameter, which is appended to the base URL defined in the HTTP connection.
Click to reveal answer
intermediate
What parameter do you use to send data in a POST request with SimpleHttpOperator?
You use the 'data' parameter to send the request body, usually as a JSON string or dictionary.
Click to reveal answer
intermediate
How can you handle the response from an API call made by SimpleHttpOperator?
You can access the response content in the task's XCom by using the 'response_filter' parameter or by pulling the XCom in downstream tasks.
Click to reveal answer
What parameter in SimpleHttpOperator defines the HTTP method to use?
Amethod
Bhttp_method
Crequest_type
Dverb
✗ Incorrect
The 'method' parameter specifies the HTTP method like GET or POST in SimpleHttpOperator.
Where does SimpleHttpOperator get the base URL for API calls?
AFrom the 'endpoint' parameter
BFrom the Airflow HTTP connection
CFrom the 'data' parameter
DFrom the DAG definition
✗ Incorrect
SimpleHttpOperator uses the base URL defined in the Airflow HTTP connection configured in the Airflow UI or environment.
Which parameter allows you to add headers to the HTTP request in SimpleHttpOperator?
Aparams
Bauth
Cdata
Dheaders
✗ Incorrect
The 'headers' parameter lets you add HTTP headers like Content-Type or Authorization.
How can you extract the API response for use in other tasks?
ABy setting 'extract_response' to True
BBy printing the response in logs
CUsing the 'response_filter' parameter or XCom
DBy saving response to a file
✗ Incorrect
SimpleHttpOperator can push the response to XCom using 'response_filter' for downstream tasks to use.
Which of these is NOT a valid HTTP method for SimpleHttpOperator?
ACONNECT
BPOST
CGET
DDELETE
✗ Incorrect
SimpleHttpOperator does not support the CONNECT method; common methods are GET, POST, PUT, DELETE, PATCH.
Explain how to configure and use SimpleHttpOperator to make a POST API call in Airflow.
Think about connection setup, HTTP method, data sending, and response handling.
You got /6 concepts.
Describe how SimpleHttpOperator integrates with Airflow's XCom system for API responses.
Focus on how data flows between tasks using XCom.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of the SimpleHttpOperator in Airflow?
easy
A. To schedule Airflow DAGs
B. To manage database connections
C. To make HTTP API calls within Airflow tasks
D. To send emails from Airflow
Solution
Step 1: Understand the role of SimpleHttpOperator
The SimpleHttpOperator is designed to perform HTTP requests like GET or POST inside Airflow tasks.
Step 2: Differentiate from other Airflow features
Scheduling DAGs, managing databases, or sending emails are handled by other operators, not SimpleHttpOperator.
Final Answer:
To make HTTP API calls within Airflow tasks -> Option C
Quick Check:
SimpleHttpOperator = API calls [OK]
Hint: SimpleHttpOperator = HTTP requests in Airflow tasks [OK]
Common Mistakes:
Confusing it with scheduling or email operators
Thinking it manages database connections
Assuming it triggers DAG runs
2. Which of the following is the correct way to create a SimpleHttpOperator task to perform a GET request to the endpoint '/status' using connection ID 'my_api'?
easy
A. SimpleHttpOperator(task_id='check_status', conn_id='my_api', endpoint='/status', method='POST')
B. SimpleHttpOperator(task_id='check_status', connection_id='my_api', url='/status', method='GET')
C. SimpleHttpOperator(task_id='check_status', http_conn_id='my_api', endpoint='/status', http_method='GET')
D. SimpleHttpOperator(task_id='check_status', http_conn_id='my_api', endpoint='/status', method='GET')
Solution
Step 1: Check parameter names for SimpleHttpOperator
The correct parameters include task_id, http_conn_id, endpoint, and method.
Step 2: Validate method and connection ID usage
SimpleHttpOperator(task_id='check_status', http_conn_id='my_api', endpoint='/status', method='GET') uses http_conn_id and method='GET', which are correct. Other options use wrong parameter names or HTTP methods.
Final Answer:
SimpleHttpOperator(task_id='check_status', http_conn_id='my_api', endpoint='/status', method='GET') -> Option D
A. The connection ID 'missing_conn' is not defined in Airflow connections; add it in UI
B. The endpoint 'info' is invalid; change it to '/'
C. The method should be lowercase 'get' instead of 'GET'
D. SimpleHttpOperator does not support GET method; use POST instead
Solution
Step 1: Understand the error about missing connection
The error indicates Airflow cannot find the connection ID 'missing_conn' in its stored connections.
Step 2: Fix by adding the connection in Airflow UI or CLI
To fix, define 'missing_conn' with the correct API base URL in Airflow connections before running the task.
Final Answer:
The connection ID 'missing_conn' is not defined in Airflow connections; add it in UI -> Option A
Quick Check:
Missing connection ID = add connection [OK]
Hint: Check Airflow connections for your http_conn_id [OK]
Common Mistakes:
Assuming endpoint name causes connection error
Changing HTTP method case unnecessarily
Thinking GET is unsupported by SimpleHttpOperator
5. You want to use SimpleHttpOperator to POST JSON data {"name": "Alice"} to endpoint '/users' using connection 'user_api'. Which is the correct way to do this?
hard
A. SimpleHttpOperator(task_id='post_user', http_conn_id='user_api', endpoint='/users', method='POST', data='{"name": "Alice"}', headers={'Content-Type': 'application/json'})
B. SimpleHttpOperator(task_id='post_user', http_conn_id='user_api', endpoint='/users', method='POST', json={'name': 'Alice'})
C. SimpleHttpOperator(task_id='post_user', http_conn_id='user_api', endpoint='/users', method='POST', data={'name': 'Alice'})
D. SimpleHttpOperator(task_id='post_user', http_conn_id='user_api', endpoint='/users', method='POST', body='{"name": "Alice"}')
Solution
Step 1: Identify how to send JSON data with SimpleHttpOperator
SimpleHttpOperator uses the data parameter for request body and headers to specify content type.
Step 2: Confirm correct JSON string and headers usage
SimpleHttpOperator(task_id='post_user', http_conn_id='user_api', endpoint='/users', method='POST', data='{"name": "Alice"}', headers={'Content-Type': 'application/json'}) sends JSON as a string in data and sets Content-Type header to 'application/json', which is correct.