http_requests
A set of basic functional wrappers around HTTP verbs
- get: customise response format
- patch
- post
get_request(url, headers={}, params={}, output='default')
Send a GET request to an HTTP API endpoint
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL to send the request to |
required |
headers
|
dict
|
A dictionary of headers to send with the request. Defaults to an empty dict. |
{}
|
params
|
dict
|
A dictionary of parameters to send with the request. Defaults to an empty dict. |
{}
|
output
|
str
|
The format in which to output the response in. Currently accepts 'default', 'json' or 'text'. 'default' does not apply any format parsing of the response. |
'default'
|
Returns:
| Name | Type | Description |
|---|---|---|
resp |
A formatted response from the HTTP request |
Raises:
| Type | Description |
|---|---|
ValueError
|
An unexpected output format was chosen. |
Source code in all_all_contributors/http_requests.py
patch_request(url, headers={}, json={}, return_json=False)
Send a PATCH request to an HTTP API endpoint
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL to send the request to |
required |
headers
|
dict
|
A dictionary of any headers to send with the request. Defaults to an empty dictionary. |
{}
|
json
|
dict
|
A dictionary containing JSON payload to send with the request. Defaults to an empty dictionary. |
{}
|
return_json
|
bool
|
Return the JSON payload response. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
resp |
A JSON formatted response from a HTTP response |
Raises:
| Type | Description |
|---|---|
HTTPError
|
An error was returned by the HTTP request |
Source code in all_all_contributors/http_requests.py
post_request(url, headers={}, json={}, return_json=False)
Send a POST request to an HTTP API endpoint
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL to send the request to |
required |
headers
|
dict
|
A dictionary of any headers to send with the request. Defaults to an empty dictionary. |
{}
|
json
|
dict
|
A dictionary containing JSON payload to send with the request. Defaults to an empty dictionary. |
{}
|
return_json
|
bool
|
Return the JSON payload response. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
resp |
A JSON formatted response from a HTTP request |
Raises:
| Type | Description |
|---|---|
HTTPError
|
An error was returned by the HTTP request |