coarnotify.http¶
HTTP layer interface and default implementation using requests lib
Classes¶
Interface for the HTTP layer |
|
Interface for the HTTP response object |
|
Implementation of the HTTP layer using the requests library. This is the default implementation |
|
Implementation fo the HTTP response object using the requests library |
Module Contents¶
- class coarnotify.http.HttpLayer¶
Interface for the HTTP layer
This defines the methods which need to be implemented in order for the client to fully operate
- abstract get(url: str, headers: dict = None, *args, **kwargs) HttpResponse ¶
Make an HTTP GET request to the supplied URL with the given headers
args and kwargs can be used to pass implementation-specific parameters
- Parameters:
url – the request URL
headers – HTTP headers as a dict to include in the request
args – argument list to pass on to the implementation
kwargs – keyword arguments to pass on to the implementation
- Returns:
HttpResponse
- abstract post(url: str, data: str, headers: dict = None, *args, **kwargs) HttpResponse ¶
Make an HTTP POST request to the supplied URL with the given body data, and headers
args and kwargs can be used to pass implementation-specific parameters
- Parameters:
url – the request URL
data – the body data
headers – HTTP headers as a dict to include in the request
args – argument list to pass on to the implementation
kwargs – keyword arguments to pass on to the implementation
- Returns:
HttpResponse
- class coarnotify.http.HttpResponse¶
Interface for the HTTP response object
This defines the methods which need to be implemented in order for the client to fully operate
- abstract header(header_name: str) str ¶
Get the value of a header from the response
- Parameters:
header_name – the name of the header
- Returns:
the header value
- property status_code: int¶
- Abstractmethod:
Get the status code of the response
- Returns:
the status code
- class coarnotify.http.RequestsHttpLayer¶
Bases:
HttpLayer
Implementation of the HTTP layer using the requests library. This is the default implementation used when no other implementation is supplied
- get(url: str, headers: dict = None, *args, **kwargs) RequestsHttpResponse ¶
Make an HTTP GET request to the supplied URL with the given headers
args and kwargs can be used to pass additional parameters to the requests.get method, such as authentication credentials, etc.
- Parameters:
url – the request URL
headers – HTTP headers as a dict to include in the request
args – argument list to pass on to requests.get
kwargs – keyword arguments to pass on to requests.get
- Returns:
HttpResponse
- post(url: str, data: str, headers: dict = None, *args, **kwargs) RequestsHttpResponse ¶
Make an HTTP POST request to the supplied URL with the given body data, and headers
args and kwargs can be used to pass additional parameters to the requests.post method, such as authentication credentials, etc.
- Parameters:
url – the request URL
data – the body data
headers – HTTP headers as a dict to include in the request
args – argument list to pass on to requests.post
kwargs – keyword arguments to pass on to requests.post
- Returns:
RequestsHttpResponse
- class coarnotify.http.RequestsHttpResponse(resp: requests.Response)¶
Bases:
HttpResponse
Implementation fo the HTTP response object using the requests library
This wraps the requests response object and provides the interface required by the client
- Parameters:
resp – response object from the requests library
- header(header_name: str) str ¶
Get the value of a header from the response
- Parameters:
header_name – the name of the header
- Returns:
the header value
- property requests_response: requests.Response¶
Get the original requests response object
- property status_code: int¶
Get the status code of the response
- Returns:
the status code