The minimal Graph API client, with the access token.
callrequests{base_url}/{path}with the token as a bearer token, and succeeds with the JSON of a 2xx answer.bodygoes as JSON,formasmultipart/form-data(as a media upload does) andparamsas query parameters.methodisGET, orPOSTwhen there is abodyor aform.- Another answer fails with the reason for its Graph error code, whose
detailisgraph_{code}and whosecauseis the Grapherrorobject, or for its HTTP status when it has no Graph error. - A
writenever repeats once the request left: a transport failure, a server error or an unreadable answer isuncertain. A refusal Meta answers before sending, such as a rate limit, is retried unlessretry=False, as a read'sretryfailures are. - A rate limit is retried after the answer's
Retry-After, however long, unlessmax_retry_afteris set: a longer wait then fails at once withRateLimited, itsretry_afterthe wait asked for. Without the header the backoff starts at 500 milliseconds. - The error's
opis the path.
Functions#
__init__#
__init__(http, access_token, base_url, max_retry_after=None) -> None| Parameter | Type | Description |
|---|---|---|
http | HttpClientService[HttpClientError, Never] | |
access_token | Redacted[str] | |
base_url | str | |
max_retry_after | Duration | None = None |
def __init__(
self,
http: HttpClientService[HttpClientError, Never],
access_token: Redacted[str],
base_url: str,
max_retry_after: Duration | None = None,
) -> None:
self._http = http
self._access_token = access_token
self._base_url = base_url
self._max_retry_after = max_retry_aftercall#
call(path, *, method=None, body=None, form=None, params=None, write=False, retry=True) -> Effect[Json, ChatError]Calls {base_url}/{path} and succeeds with the JSON of a 2xx
answer; see the class.
| Parameter | Type | Description |
|---|---|---|
path | str | |
method | Method | None = None | |
body | Mapping[str, object] | None = None | |
form | http_body.FormData | None = None | |
params | Mapping[str, str] | None = None | |
write | bool = False | |
retry | bool = True |
Returns Effect[Json, ChatError]
def call(
self,
path: str,
*,
method: Method | None = None,
body: Mapping[str, object] | None = None,
form: http_body.FormData | None = None,
params: Mapping[str, str] | None = None,
write: bool = False,
retry: bool = True,
) -> Effect[Json, ChatError]:
"""Calls ``{base_url}/{path}`` and succeeds with the JSON of a 2xx
answer; see the class."""
once = self._once(path, method, body, form, params, write)
return retry_safe(once, max_retry_after=self._max_retry_after) if retry else once