HttpInteractor
HttpInteractor ¶
Bases: Generic[TSubRequest, TResponse, TState]
, ABC
An interactor using a template method for sending HTTP requests.
auth
property
¶
auth: AuthMiddleware[TSubRequest] | None
An optional authentication middleware.
Defaults to None
.
__init__ ¶
__init__(http_client: HttpClientBase[TSubRequest], store: Store[TState])
Parameters:
Name | Type | Description | Default |
---|---|---|---|
http_client |
HttpClientBase[TSubRequest]
|
The HTTP client to use for sending requests. |
required |
store |
Store[TState]
|
The store to dispatch actions to. |
required |
side_effects
async
¶
side_effects(response: TResponse) -> None
Perform side effects after receiving the response.
Defaults to doing nothing.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
response |
TResponse
|
The response. |
required |
actions ¶
actions(response: TResponse) -> Sequence[Action]
Actions to dispatch to the store created from the response.
Defaults to empty list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
response |
TResponse
|
The response. |
required |
Returns:
Type | Description |
---|---|
Sequence[Action]
|
The actions to dispatch. |
execute
async
¶
execute() -> None
The template method performing the request.
First, it sends the request
, with the optional authentication middleware,
using the provided HttpClientBase
.
If the response is not empty, the side_effects
are performed.
After that, the actions
are dispatched to the store
.
TResponse
module-attribute
¶
TResponse = TypeVar('TResponse')
Invariant type variable for a generic response.
TSubRequest
module-attribute
¶
TSubRequest = TypeVar('TSubRequest')
Invariant type variable for a generic request.