Advanced
Direct requests
APIClient.request()
is a low-level interface to access API endpoints, and
returns a response object.
The use cases are not limited to accessing unsupported API endpoints, or reducing type conversion overhead.
There are two helper methods in the client to deal with the response object. They result in nice formats:
request_json()
returns JSON-decoded object.
request_text()
returnsstr
.
The following code snippet prints a list of dicts of active torrents from torrents/info
endpoint.
torrents = await client.request_json(
"GET",
"torrents/info",
params={
"filter": "active",
},
)
pprint.pp(torrents)
[{'hash': '75439d5de343999ab377c617c2c647902956e282',
'name': 'ubuntu-22.04.3-desktop-amd64.iso',
'size': 5037662208,
'state': 'uploading',
# some keys are omitted
}]