asyncio
Warning
async http
Async http calls are available through the self.async_http object in rule instances.
Functions
- delete(url, params=None, **kwargs)
http delete request
- Parameters:
url (
str) – Request URLparams (
Optional[Mapping[str,str]]) – Mapping, iterable of tuple of key/value pairs (e.g. dict) to be sent as parameters in the query string of the new request. Params examplekwargs (
Any) – See aiohttp request for further possible kwargs
- Return type:
_RequestContextManager- Returns:
awaitable
- get(url, params=None, **kwargs)
http get request
- Parameters:
url (
str) – Request URLparams (
Optional[Mapping[str,str]]) –Mapping, iterable of tuple of key/value pairs (e.g. dict) to be sent as parameters in the query string of the new request. Params example
kwargs (
Any) –See aiohttp request for further possible kwargs
- Return type:
_RequestContextManager- Returns:
awaitable
- get_client_session()
Return the aiohttp client session object for use in aiohttp libraries
- Return type:
ClientSession- Returns:
session object
- post(url, params=None, data=None, json=None, **kwargs)
http post request
- Parameters:
url (
str) – Request URLparams (
Optional[Mapping[str,str]]) –Mapping, iterable of tuple of key/value pairs (e.g. dict) to be sent as parameters in the query string of the new request. Params example
data (
Optional[Any]) – Dictionary, bytes, or file-like object to send in the body of the request (optional)json (
Optional[Any]) – Any json compatible python object, json and data parameters could not be used at the same time. (optional)kwargs (
Any) –See aiohttp request for further possible kwargs
- Return type:
_RequestContextManager- Returns:
awaitable
- put(url, params=None, data=None, json=None, **kwargs)
http put request
- Parameters:
url (
str) – Request URLparams (
Optional[Mapping[str,str]]) –Mapping, iterable of tuple of key/value pairs (e.g. dict) to be sent as parameters in the query string of the new request. Params example
data (
Optional[Any]) – Dictionary, bytes, or file-like object to send in the body of the request (optional)json (
Optional[Any]) – Any json compatible python object, json and data parameters could not be used at the same time. (optional)kwargs (
Any) –See aiohttp request for further possible kwargs
- Return type:
_RequestContextManager- Returns:
awaitable
Examples
import asyncio
import HABApp
class AsyncRule(HABApp.Rule):
def __init__(self):
super().__init__()
self.run.soon(self.async_func)
async def async_func(self):
await asyncio.sleep(2)
async with self.async_http.get('http://httpbin.org/get') as resp:
print(resp)
print(await resp.text())
AsyncRule()