Skip to content

Note

This module requires optional dependencies. You can install them together with pfun using pip install pfun[http]

pfun.http.HTTP dataclass

Module for making HTTP requests.

__init__(self, connector=None, cookies=None, headers=None, skip_auto_headers=None, auth=None, json_serialize=<function dumps at 0x7f6e14b1edd0>, version=HttpVersion(major=1, minor=1), cookie_jar=None, read_timeout=None, conn_timeout=None, timeout=<object object at 0x7f6e1377c1f0>, raise_for_status=False, connector_owner=True, auto_decompress=True, requote_redirect_url=False, trust_env=False, trace_configs=None)

All keyword arguments are passed to the wrapped aiohttp.ClientSession. Refer to the originial documentation for their meaning.

make_request(self, method, url, params=None, data=None, json=None, cookies=None, headers=None, skip_auto_headers=None, auth=None, allow_redirects=True, max_redirects=10, compress=None, chunked=None, expect100=False, raise_for_status=None, read_until_eof=True, proxy=None, proxy_auth=None, timeout=<object object at 0x7f6e1377c1f0>, ssl=None, verify_ssl=None, fingerprint=None, ssl_context=None, proxy_headers=None)

Make a request using HTTP verb method to URL url. All keyword arguments are passed to aiohttp.ClientSession.request. Refer to the original documentation for their meaning.

Examples:

>>> http = HTTP()
>>> http.make_request('get', 'http://foo.com').run(None)
Response(...)

Parameters:

Name Type Description Default
method str

HTTP method to use. One of get, put, post, delete, patch, head or option.

required
url str

target URL for the request

required

Returns:

Type Description
Try[ClientError, Response]

Effect that produces a Response

pfun.http.Response dataclass

The result of making a HTTP request.

content: bytes dataclass-field

The response content

cookies: BaseCookie dataclass-field

The response cookies

encoding: Union[pfun.maybe.Nothing, pfun.maybe.Just[str]] dataclass-field

Encoding of the response content if present in the header or if detectable by chardet

headers: pfun.dict.Dict[str, str] dataclass-field

The response headers

The response http link header

reason: Union[pfun.maybe.Nothing, pfun.maybe.Just[str]] dataclass-field

The reason for the request status, e.g "OK"

status: int dataclass-field

The request status

pfun.http.HasHTTP

Module provider providing the http module

pfun.http.get_session()

Get an effect that produces an aiohttp.ClientSession. Use this if you need features of aiohttp that are not supported by the high-level api.

Examples:

>>> async def use_session(session: aiohttp.ClientSession) -> str:
...     async with session.get('http://www.google.com') as response:
...         return await response.text()
>>> class Env:
...     http = HTTP()
>>> get_session().map(use_session).run(Env())
"<!doctype html> ..."

Returns:

Type Description
Depends[HasHTTP, aiohttp.ClientSession]

Effect that succeeds with aiohttp.ClientSession

pfun.http.get(url, params=None, data=None, json=None, cookies=None, headers=None, skip_auto_headers=None, auth=None, allow_redirects=True, max_redirects=10, compress=None, chunked=None, expect100=False, raise_for_status=None, read_until_eof=True, proxy=None, proxy_auth=None, timeout=<object object at 0x7f6e1377c1f0>, ssl=None, verify_ssl=None, fingerprint=None, ssl_context=None, proxy_headers=None)

Make a HTTP get request to URL url. All keyword arguments are passed to aiohttp.ClientSession.request. Refer to the original documentation for their meaning.

Examples:

>>> class Env:
...     http = HTTP()
>>> get('http://foo.com').run(Env())
Response(...)

Parameters:

Name Type Description Default
url str

target URL for the request

required

Returns:

Type Description
Effect[HasHTTP, ClientError, Response]

Effect that produces a Response

pfun.http.put(url, params=None, data=None, json=None, cookies=None, headers=None, skip_auto_headers=None, auth=None, allow_redirects=True, max_redirects=10, compress=None, chunked=None, expect100=False, raise_for_status=None, read_until_eof=True, proxy=None, proxy_auth=None, timeout=<object object at 0x7f6e1377c1f0>, ssl=None, verify_ssl=None, fingerprint=None, ssl_context=None, proxy_headers=None)

Make a HTTP put request to URL url. All keyword arguments are passed to aiohttp.ClientSession.request. Refer to the original documentation for their meaning.

Examples:

>>> class Env:
...     http = HTTP()
>>> put('http://foo.com').run(Env())
Response(...)

Parameters:

Name Type Description Default
url str

target URL for the request

required

Returns:

Type Description
Effect[HasHTTP, ClientError, Response]

Effect that produces a Response

pfun.http.post(url, params=None, data=None, json=None, cookies=None, headers=None, skip_auto_headers=None, auth=None, allow_redirects=True, max_redirects=10, compress=None, chunked=None, expect100=False, raise_for_status=None, read_until_eof=True, proxy=None, proxy_auth=None, timeout=<object object at 0x7f6e1377c1f0>, ssl=None, verify_ssl=None, fingerprint=None, ssl_context=None, proxy_headers=None)

Make a HTTP post request to URL url. All keyword arguments are passed to aiohttp.ClientSession.request. Refer to the original documentation for their meaning.

Examples:

>>> class Env:
...     http = HTTP()
>>> post('http://foo.com').run(Env())
Response(...)

Parameters:

Name Type Description Default
url str

target URL for the request

required

Returns:

Type Description
Effect[HasHTTP, ClientError, Response]

Effect that produces a Response

pfun.http.delete(url, params=None, data=None, json=None, cookies=None, headers=None, skip_auto_headers=None, auth=None, allow_redirects=True, max_redirects=10, compress=None, chunked=None, expect100=False, raise_for_status=None, read_until_eof=True, proxy=None, proxy_auth=None, timeout=<object object at 0x7f6e1377c1f0>, ssl=None, verify_ssl=None, fingerprint=None, ssl_context=None, proxy_headers=None)

Make a HTTP delete request to URL url. All keyword arguments are passed to aiohttp.ClientSession.request. Refer to the original documentation for their meaning.

Examples:

>>> class Env:
...     http = HTTP()
>>> delete('http://foo.com').run(Env())
Response(...)

Parameters:

Name Type Description Default
url str

target URL for the request

required

Returns:

Type Description
Effect[HasHTTP, ClientError, Response]

Effect that produces a Response

pfun.http.head(url, params=None, data=None, json=None, cookies=None, headers=None, skip_auto_headers=None, auth=None, allow_redirects=True, max_redirects=10, compress=None, chunked=None, expect100=False, raise_for_status=None, read_until_eof=True, proxy=None, proxy_auth=None, timeout=<object object at 0x7f6e1377c1f0>, ssl=None, verify_ssl=None, fingerprint=None, ssl_context=None, proxy_headers=None)

Make a HTTP head request to URL url. All keyword arguments are passed to aiohttp.ClientSession.request. Refer to the original documentation for their meaning.

Examples:

>>> class Env:
...     http = HTTP()
>>> head('http://foo.com').run(Env())
Response(...)

Parameters:

Name Type Description Default
url str

target URL for the request

required

Returns:

Type Description
Effect[HasHTTP, ClientError, Response]

Effect that produces a Response

pfun.http.patch(url, params=None, data=None, json=None, cookies=None, headers=None, skip_auto_headers=None, auth=None, allow_redirects=True, max_redirects=10, compress=None, chunked=None, expect100=False, raise_for_status=None, read_until_eof=True, proxy=None, proxy_auth=None, timeout=<object object at 0x7f6e1377c1f0>, ssl=None, verify_ssl=None, fingerprint=None, ssl_context=None, proxy_headers=None)

Make a HTTP patch request to URL url. All keyword arguments are passed to aiohttp.ClientSession.request. Refer to the original documentation for their meaning.

Examples:

>>> class Env:
...     http = HTTP()
>>> patch('http://foo.com').run(Env())
Response(...)

Parameters:

Name Type Description Default
url str

target URL for the request

required

Returns:

Type Description
Effect[HasHTTP, ClientError, Response]

Effect that produces a Response

pfun.http.options(url, params=None, data=None, json=None, cookies=None, headers=None, skip_auto_headers=None, auth=None, allow_redirects=True, max_redirects=10, compress=None, chunked=None, expect100=False, raise_for_status=None, read_until_eof=True, proxy=None, proxy_auth=None, timeout=<object object at 0x7f6e1377c1f0>, ssl=None, verify_ssl=None, fingerprint=None, ssl_context=None, proxy_headers=None)

Make a HTTP options request to URL url. All keyword arguments are passed to aiohttp.ClientSession.request. Refer to the original documentation for their meaning.

Examples:

>>> class Env:
...     http = HTTP()
>>> options('http://foo.com').run(Env())
Response(...)

Parameters:

Name Type Description Default
url str

target URL for the request

required

Returns:

Type Description
Effect[HasHTTP, ClientError, Response]

Effect that produces a Response