HTTP Operators¶
The following code examples use the http_default
connection which means the requests are sent against
httpbin site to perform basic HTTP operations.
HttpSensor¶
Use the HttpSensor
to poke until the response_check
callable evaluates
to true
.
Here we are poking until httpbin gives us a response text containing httpbin
.
SimpleHttpOperator¶
Use the SimpleHttpOperator
to call HTTP requests and get
the response text back.
In the first example we are calling a POST
with json data and succeed when we get the same json data back
otherwise the task will fail.
Here we are calling a GET
request and pass params to it. The task will succeed regardless of the response text.
SimpleHttpOperator returns the response body as text by default. If you want to modify the response before passing
it on the next task downstream use response_filter
. This is useful if:
the API you are consuming returns a large JSON payload and you're interested in a subset of the data
the API returns data in xml or csv and you want to convert it to JSON
you're interested in the headers of the response instead of the body
Below is an example of retrieving data from a REST API and only returning a nested property instead of the full response body.
In the third example we are performing a PUT
operation to put / set data according to the data that is being
provided to the request.
In this example we call a DELETE
operation to the delete
endpoint. This time we are passing form data to the
request.
Here we pass form data to a POST
operation which is equal to a usual form submit.