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
- model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[dict[str, FieldInfo]] = {'constant_replacers': FieldInfo(annotation=Mapping[str, Callable[list, str]], required=False, default_factory=dict), 'data': FieldInfo(annotation=Mapping[str, Any], required=False, default_factory=dict), 'headers': FieldInfo(annotation=Mapping[str, Any], required=False, default_factory=dict), 'log_response': FieldInfo(annotation=bool, required=False, default=False), 'params': FieldInfo(annotation=Mapping[str, Any], required=False, default_factory=dict), 'post': FieldInfo(annotation=bool, required=False, default=True), 'url': FieldInfo(annotation=str, required=True)}
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].
This replaces Model.__fields__ from Pydantic V1.
- 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], str]) – The replacing function.
- Returns:
The replaced data.
- Return type:
Dict[str, Any]
- url: str