AsyncClient
An async version of Client that creates ASGIRequests and calls through an async request path.
Attributes
| Attribute | Type | Description |
|---|---|---|
| handler | [AsyncClientHandler](asyncclienthandler.md?sid=django_test_client_asyncclienthandler) | The asynchronous request handler used to process ASGI scopes and return responses. |
| raise_request_exception | boolean = True | Flag determining whether to re-raise exceptions that occur during the request processing. |
| exc_info | tuple or None = None | Stores exception information captured during the request lifecycle for later inspection. |
| extra | dict or None = None | Stores additional keyword arguments passed to request methods to be used in the request scope. |
| headers | dict or None = None | Stores the HTTP headers to be included in the outgoing asynchronous requests. |
Constructor
Signature
def AsyncClient(
enforce_csrf_checks: boolean = False,
raise_request_exception: boolean = True,
headers: dict = None,
query_params: dict = None,
defaults: dict
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| enforce_csrf_checks | boolean = False | Whether to enforce CSRF validation on requests. |
| raise_request_exception | boolean = True | Whether to raise exceptions that occur during the request process. |
| headers | dict = None | Default headers to include in every request. |
| query_params | dict = None | Default query parameters to include in every request. |
| defaults | dict | Additional default keyword arguments for the request factory. |
Methods
request()
@classmethod
def request(
**request: dict
) - > [HttpResponse](../../http/response/httpresponse.md?sid=django_http_response_httpresponse)
Make a generic request. Compose the scope dictionary and pass to the handler, return the result of the handler. Assume defaults for the query environment, which can be overridden using the arguments to the request.
Parameters
| Name | Type | Description |
|---|---|---|
| **request | dict | Key-value pairs used to construct the ASGI scope and override default request environment settings. |
Returns
| Type | Description |
|---|---|
[HttpResponse](../../http/response/httpresponse.md?sid=django_http_response_httpresponse) | The response object populated with template data, context, and resolver match information. |
get()
@classmethod
def get(
path: str,
data: dict = None,
follow: bool = False,
secure: bool = False,
headers: dict = None,
query_params: dict = None
) - > [HttpResponse](../../http/response/httpresponse.md?sid=django_http_response_httpresponse)
Request a response from the server using GET.
Parameters
| Name | Type | Description |
|---|---|---|
| path | str | The URL path to request from the server. |
| data | dict = None | Dictionary of query parameters to be appended to the URL. |
| follow | bool = False | Whether to automatically follow HTTP redirects until a non-3xx status is reached. |
| secure | bool = False | If True, the request will be performed over HTTPS. |
| headers | dict = None | Additional HTTP headers to include in the request. |
| query_params | dict = None | Explicit query string parameters to include in the request scope. |
Returns
| Type | Description |
|---|---|
[HttpResponse](../../http/response/httpresponse.md?sid=django_http_response_httpresponse) | The server response, potentially after following redirects if requested. |
post()
@classmethod
def post(
path: str,
data: dict|str = None,
content_type: str = multipart/form-data,
follow: bool = False
) - > [HttpResponse](../../http/response/httpresponse.md?sid=django_http_response_httpresponse)
Request a response from the server using POST.
Parameters
| Name | Type | Description |
|---|---|---|
| path | str | The URL path where the data should be posted. |
| data | `dict | str` = None |
| content_type | str = multipart/form-data | The MIME type of the request body. |
| follow | bool = False | Whether to follow redirects triggered by the POST request. |
Returns
| Type | Description |
|---|---|
[HttpResponse](../../http/response/httpresponse.md?sid=django_http_response_httpresponse) | The server response resulting from the POST submission. |
head()
@classmethod
def head(
path: str
) - > [HttpResponse](../../http/response/httpresponse.md?sid=django_http_response_httpresponse)
Request a response from the server using HEAD.
Parameters
| Name | Type | Description |
|---|---|---|
| path | str | The URL path to query for header information. |
Returns
| Type | Description |
|---|---|
[HttpResponse](../../http/response/httpresponse.md?sid=django_http_response_httpresponse) | The response headers from the server without the response body. |
options()
@classmethod
def options(
path: str
) - > [HttpResponse](../../http/response/httpresponse.md?sid=django_http_response_httpresponse)
Request a response from the server using OPTIONS.
Parameters
| Name | Type | Description |
|---|---|---|
| path | str | The URL path to query for allowed methods and capabilities. |
Returns
| Type | Description |
|---|---|
[HttpResponse](../../http/response/httpresponse.md?sid=django_http_response_httpresponse) | The response describing the communication options available for the target URL. |
put()
@classmethod
def put(
path: str
) - > [HttpResponse](../../http/response/httpresponse.md?sid=django_http_response_httpresponse)
Send a resource to the server using PUT.
Parameters
| Name | Type | Description |
|---|---|---|
| path | str | The URL path of the resource to be created or replaced. |
Returns
| Type | Description |
|---|---|
[HttpResponse](../../http/response/httpresponse.md?sid=django_http_response_httpresponse) | The response from the server after the resource update attempt. |
patch()
@classmethod
def patch(
path: str
) - > [HttpResponse](../../http/response/httpresponse.md?sid=django_http_response_httpresponse)
Send a resource to the server using PATCH.
Parameters
| Name | Type | Description |
|---|---|---|
| path | str | The URL path of the resource to be partially modified. |
Returns
| Type | Description |
|---|---|
[HttpResponse](../../http/response/httpresponse.md?sid=django_http_response_httpresponse) | The response from the server after applying the partial update. |
delete()
@classmethod
def delete(
path: str
) - > [HttpResponse](../../http/response/httpresponse.md?sid=django_http_response_httpresponse)
Send a DELETE request to the server.
Parameters
| Name | Type | Description |
|---|---|---|
| path | str | The URL path of the resource to be removed. |
Returns
| Type | Description |
|---|---|
[HttpResponse](../../http/response/httpresponse.md?sid=django_http_response_httpresponse) | The response from the server confirming or denying the deletion. |
trace()
@classmethod
def trace(
path: str
) - > [HttpResponse](../../http/response/httpresponse.md?sid=django_http_response_httpresponse)
Send a TRACE request to the server.
Parameters
| Name | Type | Description |
|---|---|---|
| path | str | The URL path to perform a diagnostic trace against. |
Returns
| Type | Description |
|---|---|
[HttpResponse](../../http/response/httpresponse.md?sid=django_http_response_httpresponse) | The response containing the loop-back message of the request entity. |