corehttp.rest package¶
- class corehttp.rest.AsyncHttpResponse[source]¶
Abstract base class for Async HTTP responses.
Use this abstract base class to create your own transport responses.
Responses implementing this ABC are returned from your async client’s send_request method if you pass in an
HttpRequest
>>> from corehttp.rest import HttpRequest >>> request = HttpRequest('GET', 'http://www.example.com') <HttpRequest [GET], url: 'http://www.example.com'> >>> response = await client.send_request(request) <AsyncHttpResponse: 200 OK>
- abstract async iter_bytes(**kwargs: Any) AsyncIterator[bytes] [source]¶
Asynchronously iterates over the response’s bytes. Will decompress in the process.
- Returns:
An async iterator of bytes from the response
- Return type:
AsyncIterator[bytes]
- abstract async iter_raw(**kwargs: Any) AsyncIterator[bytes] [source]¶
Asynchronously iterates over the response’s bytes. Will not decompress in the process.
- Returns:
An async iterator of bytes from the response
- Return type:
AsyncIterator[bytes]
- abstract json() Any ¶
Returns the whole body as a json object.
- Returns:
The JSON deserialized response body
- Return type:
any
- Raises:
json.decoder.JSONDecodeError or ValueError (in python 2.7) if object is not JSON decodable –
- abstract raise_for_status() None ¶
Raises an HttpResponseError if the response has an error status code.
If response is good, does nothing.
- Raises:
–
- abstract async read() bytes [source]¶
Read the response’s bytes into memory.
- Returns:
The response’s bytes
- Return type:
- abstract property content: bytes¶
Return the response’s content in bytes.
- Return type:
- Returns:
The response’s content in bytes.
- abstract property content_type: str | None¶
The content type of the response.
- Return type:
- Returns:
The content type of the response.
- abstract property encoding: str | None¶
Returns the response encoding.
- Returns:
The response encoding. We either return the encoding set by the user, or try extracting the encoding from the response’s content type. If all fails, we return None.
- Return type:
optional[str]
- abstract property headers: MutableMapping[str, str]¶
The response headers. Must be case-insensitive.
- abstract property is_closed: bool¶
Whether the network connection has been closed yet.
- Return type:
- Returns:
Whether the network connection has been closed yet.
- abstract property is_stream_consumed: bool¶
Whether the stream has been consumed.
- Return type:
- Returns:
Whether the stream has been consumed.
- abstract property reason: str¶
The reason phrase for this response.
- Return type:
- Returns:
The reason phrase for this response.
- abstract property request: HttpRequest¶
The request that resulted in this response.
- Return type:
- Returns:
The request that resulted in this response.
- class corehttp.rest.HttpRequest(method: str, url: str, *, params: Mapping[str, str | int | float | bool | None | Sequence[str | int | float | bool | None]] | None = None, headers: MutableMapping[str, str] | None = None, json: Any = None, content: str | bytes | Iterable[bytes] | AsyncIterable[bytes] | None = None, data: Dict[str, Any] | None = None, files: Mapping[str, str | bytes | IO[str] | IO[bytes] | Tuple[str | None, str | bytes | IO[str] | IO[bytes]] | Tuple[str | None, str | bytes | IO[str] | IO[bytes], str | None]] | Sequence[Tuple[str, str | bytes | IO[str] | IO[bytes] | Tuple[str | None, str | bytes | IO[str] | IO[bytes]] | Tuple[str | None, str | bytes | IO[str] | IO[bytes], str | None]]] | None = None, **kwargs: Any)[source]¶
An HTTP request.
It should be passed to your client’s send_request method.
>>> from corehttp.rest import HttpRequest >>> request = HttpRequest('GET', 'http://www.example.com') <HttpRequest [GET], url: 'http://www.example.com'> >>> response = client.send_request(request) <HttpResponse: 200 OK>
- Parameters:
- Keyword Arguments:
params (mapping) – Query parameters to be mapped into your URL. Your input should be a mapping of query name to query value(s).
headers (mapping) – HTTP headers you want in your request. Your input should be a mapping of header name to header value.
json (any) – A JSON serializable object. We handle JSON-serialization for your object, so use this for more complicated data structures than data.
content (str or bytes or iterable[bytes] or asynciterable[bytes]) – Content you want in your request body. Think of it as the kwarg you should input if your data doesn’t fit into json, data, or files. Accepts a bytes type, or a generator that yields bytes.
data (dict) – Form data you want in your request body. Use for form-encoded data, i.e. HTML forms.
files (mapping) – Files you want to in your request body. Use for uploading files with multipart encoding. Your input should be a mapping of file name to file content. Use the data kwarg in addition if you want to include non-file data files as part of your request.
- Variables:
- class corehttp.rest.HttpResponse[source]¶
Abstract base class for HTTP responses.
Use this abstract base class to create your own transport responses.
Responses implementing this ABC are returned from your client’s send_request method if you pass in an
HttpRequest
>>> from corehttp.rest import HttpRequest >>> request = HttpRequest('GET', 'http://www.example.com') <HttpRequest [GET], url: 'http://www.example.com'> >>> response = client.send_request(request) <HttpResponse: 200 OK>
- abstract iter_bytes(**kwargs: Any) Iterator[bytes] [source]¶
Iterates over the response’s bytes. Will decompress in the process.
- Returns:
An iterator of bytes from the response
- Return type:
Iterator[str]
- abstract iter_raw(**kwargs: Any) Iterator[bytes] [source]¶
Iterates over the response’s bytes. Will not decompress in the process.
- Returns:
An iterator of bytes from the response
- Return type:
Iterator[str]
- abstract json() Any ¶
Returns the whole body as a json object.
- Returns:
The JSON deserialized response body
- Return type:
any
- Raises:
json.decoder.JSONDecodeError or ValueError (in python 2.7) if object is not JSON decodable –
- abstract raise_for_status() None ¶
Raises an HttpResponseError if the response has an error status code.
If response is good, does nothing.
- Raises:
–
- abstract property content: bytes¶
Return the response’s content in bytes.
- Return type:
- Returns:
The response’s content in bytes.
- abstract property content_type: str | None¶
The content type of the response.
- Return type:
- Returns:
The content type of the response.
- abstract property encoding: str | None¶
Returns the response encoding.
- Returns:
The response encoding. We either return the encoding set by the user, or try extracting the encoding from the response’s content type. If all fails, we return None.
- Return type:
optional[str]
- abstract property headers: MutableMapping[str, str]¶
The response headers. Must be case-insensitive.
- abstract property is_closed: bool¶
Whether the network connection has been closed yet.
- Return type:
- Returns:
Whether the network connection has been closed yet.
- abstract property is_stream_consumed: bool¶
Whether the stream has been consumed.
- Return type:
- Returns:
Whether the stream has been consumed.
- abstract property reason: str¶
The reason phrase for this response.
- Return type:
- Returns:
The reason phrase for this response.
- abstract property request: HttpRequest¶
The request that resulted in this response.
- Return type:
- Returns:
The request that resulted in this response.