Bjorn Olsen created AIRFLOW-6327:
------------------------------------
Summary: http_hook: Add json requests payload
Key: AIRFLOW-6327
URL: https://issues.apache.org/jira/browse/AIRFLOW-6327
Project: Apache Airflow
Issue Type: Improvement
Components: hooks
Affects Versions: 1.10.6
Reporter: Bjorn Olsen
Assignee: Bjorn Olsen
Python requests library allows a user to send json-encoded Python objects by
making use of the "json=" parameter to a request.
This handles JSON encoding of the payload and setting the correct content type
header.
Example:
{code:python}
response = requests.post('https://httpbin.org/post', json={'key':'value'})
json_response = response.json()
json_response['data'] '{"key": "value"}'
json_response['headers']['Content-Type'] 'application/json'
{code}
http_hook.run() does not yet have the json= parameter which is inconvenient as
then we have to pass the "data=" parameter using json.dumps and specify the
correct headers.
It would be better if we can just do something like the below and let the
Requests library ensure the request is valid:
{code:python}
obj = {'a':1, 'b': 'abc', 'c': [1, 2, {"d":10}]}
response = hook.run(
endpoint,
json=obj)
{code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)