HttpRequest Class 
Represents an HTTP request.
URL can be given without query parameters, to be added later using "format_parameters".
Constructor
HttpRequest(method: str, url: str, headers: Mapping[str, str] | None = None, files: Any | None = None, data: bytes | str | Dict[str, str | int] | None = None)Parameters
| Name | Description | 
|---|---|
| method 
				Required
			 | HTTP method (GET, HEAD, etc.) | 
| url 
				Required
			 | At least complete scheme/host/path | 
| headers | HTTP headers Default value: None | 
| files | Dictionary of  Default value: None | 
| data | Body to be sent. Default value: None | 
Methods
| format_parameters | Format parameters into a valid query string. It's assumed all parameters have already been quoted as valid URL strings. | 
| prepare_multipart_body | Will prepare the body of this request according to the multipart information. This call assumes the on_request policies have been applied already in their correct context (sync/async) Does nothing if "set_multipart_mixed" was never called. | 
| serialize | Serialize this request using application/http spec. | 
| set_bytes_body | Set generic bytes as the body of the request. Will set content-length. | 
| set_formdata_body | Set form-encoded data as the body of the request. | 
| set_json_body | Set a JSON-friendly object as the body of the request. | 
| set_multipart_mixed | Set the part of a multipart/mixed. Only supported args for now are HttpRequest objects. boundary is optional, and one will be generated if you don't provide one. Note that no verification are made on the boundary, this is considered advanced enough so you know how to respect RFC1341 7.2.1 and provide a correct boundary. Any additional kwargs will be passed into the pipeline context for per-request policy configuration. | 
| set_streamed_data_body | Set a streamable data body. | 
| set_text_body | Set a text as body of the request. | 
| set_xml_body | Set an XML element tree as the body of the request. | 
format_parameters
Format parameters into a valid query string. It's assumed all parameters have already been quoted as valid URL strings.
format_parameters(params: Dict[str, str]) -> NoneParameters
| Name | Description | 
|---|---|
| params 
				Required
			 | A dictionary of parameters. | 
prepare_multipart_body
Will prepare the body of this request according to the multipart information.
This call assumes the on_request policies have been applied already in their correct context (sync/async)
Does nothing if "set_multipart_mixed" was never called.
prepare_multipart_body(content_index: int = 0) -> intParameters
| Name | Description | 
|---|---|
| content_index | The current index of parts within the batch message. Default value: 0 | 
Returns
| Type | Description | 
|---|---|
| The updated index after all parts in this request have been added. | 
serialize
Serialize this request using application/http spec.
serialize() -> bytesReturns
| Type | Description | 
|---|---|
| The requests serialized as HTTP low-level message in bytes. | 
set_bytes_body
Set generic bytes as the body of the request.
Will set content-length.
set_bytes_body(data: bytes) -> NoneParameters
| Name | Description | 
|---|---|
| data 
				Required
			 | The request field data. | 
set_formdata_body
Set form-encoded data as the body of the request.
set_formdata_body(data: Dict[str, str] | None = None) -> NoneParameters
| Name | Description | 
|---|---|
| data | The request field data. Default value: None | 
set_json_body
Set a JSON-friendly object as the body of the request.
set_json_body(data: Any) -> NoneParameters
| Name | Description | 
|---|---|
| data 
				Required
			 | A JSON serializable object | 
set_multipart_mixed
Set the part of a multipart/mixed.
Only supported args for now are HttpRequest objects.
boundary is optional, and one will be generated if you don't provide one. Note that no verification are made on the boundary, this is considered advanced enough so you know how to respect RFC1341 7.2.1 and provide a correct boundary.
Any additional kwargs will be passed into the pipeline context for per-request policy configuration.
set_multipart_mixed(*requests: HttpRequest, policies: List[SansIOHTTPPolicy[HTTPRequestType, HTTPResponseType]] | None = None, boundary: str | None = None, **kwargs: Any) -> NoneParameters
| Name | Description | 
|---|---|
| requests 
				Required
			 | The requests to add to the multipart/mixed | 
Keyword-Only Parameters
| Name | Description | 
|---|---|
| policies | SansIOPolicy to apply at preparation time Default value: None | 
| boundary | Optional boundary Default value: None | 
set_streamed_data_body
Set a streamable data body.
set_streamed_data_body(data: Any) -> NoneParameters
| Name | Description | 
|---|---|
| data 
				Required
			 | 
				<xref:stream> or 
				<xref:generator> or 
				<xref:asyncgenerator>
		 The request field data. | 
set_text_body
Set a text as body of the request.
set_text_body(data: str) -> NoneParameters
| Name | Description | 
|---|---|
| data 
				Required
			 | A text to send as body. | 
set_xml_body
Set an XML element tree as the body of the request.
set_xml_body(data: Any) -> NoneParameters
| Name | Description | 
|---|---|
| data 
				Required
			 | 
				<xref:<xref:XML node>>
		 The request field data. |