Skip to content

Commit

Permalink
hints in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Tishka17 committed May 21, 2024
1 parent ca0d325 commit 87a6f0f
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,40 @@ To set same behavior for all methods inherit from BoundMethod class, override `_
### Other params

You can use different body argument name if you want. Just pass `body_name` to the decorator.


### Special cases

#### `None` in query params

By default, AioHTTP doesn't skip query params, you can customize that overriding `_pre_process_request` in Method class

```python
class NoneAwareAiohttpMethod(AiohttpMethod):
async def _pre_process_request(self, request: HttpRequest) -> HttpRequest:
request.query_params = {
k: v for k, v in request.query_params.items() if v is not None
}
return request


class Client(AiohttpClient):
method_class = NoneAwareAiohttpMethod
```

#### Handling `No content`

By default, en each method json response is expected. Sometime you expect no content from server. Especially for 204.
You can handle it by overriding `_response_body` method, e.g.:

```python
class NoneAwareRequestsMethod(RequestsMethod):
def _response_body(self, response: Response) -> Any:
if response.status_code == http.HTTPStatus.NO_CONTENT:
return None
return super()._response_body(response)


class Client(RequestsClient):
method_class = NoneAwareRequestsMethod
```

0 comments on commit 87a6f0f

Please sign in to comment.