http
— functions for accessing external web services
This module contains functions for accessing HTTP endpoints on the web, allowing application developers to create a wide variety of features for end users. In simple cases the DL-7450 could fetch splashscreen content from content provider hosted in the cloud or within a corporate network.
Coming soon
In this preview only the GET and POST methods are available. In the first release this module will also support PATCH and DELETE requests.
Synchronous HTTP requests
These functions perform an HTTP request and return the response.
- http.get(url, headers=None, data=None)
Send an HTTP GET request to the given
url
.
- http.post(url, headers=None, data=None)
Send an HTTP POST request to the given
url
.
For all these request functions:
A
dict
of key-value pairs can be specified for theheaders
. These will each be listed askey: value
in the HTTP request header.Any
bytes
-like data specified indata
will constitute the body of the request.They all return an http.Response object populated with the result and response of the request.
Program flow will pause until a response is received from the server, or the request fails.
A maximum of 16 HTTP requests can be made by a running Python app. Attempting to
create further requests will cause the request to immediately fail with
status_code
89, corresponding to CURLE_NO_CONNECTION_AVAILABLE
.
If a request is sent without any data, a Content-Length: 0
header will
automatically be included with the request.
It is up to the user to ensure that all specified arguments are valid. For
instance, sending a GET request with a body has undefined semantics, but the
user may still provide data
for an http.get()
call if it suits their
use case.
Coming soon
The PATCH and DELETE request functions have not yet been implemented. They will act in a similar way to the GET and POST requests.
- http.patch(url, headers=None, data=None)
Send an HTTP PATCH request to the given
url
.
- http.delete(url, headers=None, data=None)
Send an HTTP DELETE request to the given
url
.
Asynchronous HTTP requests
These functions perform an HTTP request and return the response.
- http.get_async(url, on_complete, headers=None, data=None)
Send an HTTP GET request to the given
url
without blocking program flow.
- http.post_async(url, on_complete, headers=None, data=None)
Send an HTTP POST request to the given
url
without blocking program flow.
These functions have all the same attributes as their synchronous counterparts, but:
An additional
on_complete
parameter must be specified. This must be a Python callable that takes one parameter.Upon the completion of the request, the
on_complete
function will be called, with the http.Response that would have been returned from the corresponding synchronous function as its only argument.These functions will return a control object that will allow the user to cancel the request, instead of an http.Response object.
Coming soon
Asynchronous versions of PATCH and DELETE are planned:
- http.patch_async(url, on_complete, headers=None, data=None)
Send an HTTP PATCH request to the given
url
without blocking program flow.
- http.delete_async(url, on_complete, headers=None, data=None)
Send an HTTP DELETE request to the given
url
without blocking program flow.