Introducing first class support for API client definitions
Each client definition can support multiple API endpoints and optionally share state (auth, session, etc).
Example:
python
from dataclasses import dataclass
import quickapi
An example type that will be part of the API response
dataclass
class Fact:
fact: str
length: int
What the API response should look like
dataclass
class ResponseBody:
current_page: int
data: list[Fact]
We define an API endpoint
class GetFactsApi(quickapi.BaseApi[ResponseBody]):
url = "/facts"
response_body = ResponseBody
And now our API client
class ExampleClient(quickapi.BaseClient):
base_url = "https://example.com"
get_facts = quickapi.ApiEndpoint(GetFactsApi)
Other endpoints would follow here:
submit_fact = quickapi.ApiEndpoint(SubmitFactApi)
And you can use it like this:
python
client = ExampleClient()
response = client.get_facts()
`response` is fully typed and conforms to our `ResponseBody` definition
assert isinstance(response.body, ResponseBody)
assert isinstance(response.body.data[0], Fact)
`reveal_type(response.body)` returns `Revealed type is 'ResponseBody'` too,
which means full typing and IDE support.
What's changed
* Improve API client definition and usage by martinn in https://github.com/martinn/quickapiclient/pull/17
* Ensure we support `kwargs` for API client endpoints by martinn in https://github.com/martinn/quickapiclient/pull/20
* Documentation improvements by martinn in https://github.com/martinn/quickapiclient/pull/19
**Full Changelog**: https://github.com/martinn/quickapiclient/compare/v0.0.15...v0.5.0