RequestHandler (autotransform.util.request)¶
A utility for performing REST API requests.
- class autotransform.util.request.RequestHandler(*, url: str, constant_replacers: Mapping[str, Callable[[str], str]] = None, data: Mapping[str, Any] = None, headers: Mapping[str, Any] = None, log_response: bool = False, params: Mapping[str, Any] = None, post: bool = True)¶
Bases:
BaseModel
Performs REST API requests, replacing values with things like environment variables
- url¶
The URL to send a request to.
- Type:
str
- constant_ replacers
The replacers to apply to all usages of this handler. Defaults to {}.
- Type:
optional, Mapping[str, Callable[[str], str]]
- data¶
Data to include in the request. Defaults to {}.
- Type:
optional, Mapping[str, Any]
- headers¶
Headers to include in the request. Defaults to {}.
- Type:
optional, Mapping[str, Any]
- log_response¶
Indicates whether to log the response using DebugEvent. Defaults to False.
- Type:
optional, bool
- params¶
Params to include in the request. Defaults to {}.
- Type:
optional, Mapping[str, Any]
- post¶
Whether to send the request as a POST. Defaults to True.
- Type:
optional, bool
- constant_replacers: Mapping[str, Callable[[str], str]]¶
- data: Mapping[str, Any]¶
- get_response(replacers: Dict[str, Callable[[str], str]]) Response ¶
Gets the value from a REST API request.
- Parameters:
replacers (Dict[str, Callable[[str], str]]) – The replacers to use for the request.
- Returns:
The response to the request.
- Return type:
requests.Response
- headers: Mapping[str, Any]¶
- log_response: bool¶
- params: Mapping[str, Any]¶
- post: bool¶
- static replace_values(data: Mapping[str, Any], identifier: str, replacer: Callable[[str], str]) Dict[str, Any] ¶
Replaces values in a dictionary with values from a replacing function.
- Parameters:
data (Mapping[str, Any]) – The data to replace values for.
identifier (str) – The identifier of the type of value.
replacer (Callable[[str], Any]) – The replacing function.
- Returns:
The replaced data.
- Return type:
Dict[str, Any]
- url: str¶