Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,13 @@ These provide a `requests`/`httpx`-compatible interface with enhancements:
```python
from kognic.auth.requests import BaseApiClient


class MyApiClient(BaseApiClient):
def get_resource(self, resource_id: str):
response = self.session.get(f"https://api.app.kognic.com/v1/resources/{resource_id}")
return response.json()


# Usage with environment variables
client = MyApiClient()

Expand All @@ -307,12 +309,14 @@ client = MyApiClient(auth=("my-client-id", "my-client-secret"), scopes=["api:rea
```python
from kognic.auth.httpx import BaseAsyncApiClient


class MyAsyncApiClient(BaseAsyncApiClient):
async def get_resource(self, resource_id: str):
session = await self.session
response = await session.get(f"https://api.app.kognic.com/v1/resources/{resource_id}")
return response.json()


# Usage as async context manager
async with MyAsyncApiClient() as client:
resource = await client.get_resource("123")
Expand All @@ -339,10 +343,12 @@ serialize_body([1, 2, 3]) # [1, 2, 3]
# For Pydantic models, convert to dict first
from pydantic import BaseModel


class CreateRequest(BaseModel):
name: str
value: int


request = CreateRequest(name="test", value=42)
serialize_body(request.model_dump()) # {"name": "test", "value": 42}
```
Expand Down