nemoguardrails.http.types

View as Markdown

Dependency-free request and response values for outbound HTTP calls.

Module Contents

Classes

NameDescription
HTTPRequestDescribe an outbound HTTP request without transport-specific objects.
HTTPResponseA materialized, transport-neutral HTTP response.
HTTPTLSConfigConfigure TLS verification and optional mutual authentication.

API

class nemoguardrails.http.types.HTTPRequest(
method: str,
url: str,
headers: typing.Mapping[str, str] | None = None,
params: typing.Mapping[str, typing.Any] | None = None,
json: typing.Any = None,
content: bytes | str | None = None,
timeout: float | None = None
)
Dataclass

Describe an outbound HTTP request without transport-specific objects.

The value is suitable for status-error context and deterministic test assertions. It does not perform a request itself.

content
bytes | str | None = None
headers
Mapping[str, str] | None = None
method
str
params
Mapping[str, Any] | None = None
timeout
float | None = None
url
str
class nemoguardrails.http.types.HTTPResponse(
status_code: int,
headers: typing.Mapping[str, str] = dict(),
content: bytes = b'',
extensions: typing.Mapping[str, typing.Any] = dict()
)
Dataclass

A materialized, transport-neutral HTTP response.

content owns the response bytes, so callers can decode the body after the transport or client context has closed. extensions carries optional non-portable metadata without changing the core contract.

content
bytes = b''
extensions
Mapping[str, Any] = field(default_factory=dict)
headers
Mapping[str, str] = field(default_factory=dict)
is_success
bool

Return whether the status code is in the 2xx range.

status_code
int
text
str

Decode the response body using its declared charset or UTF-8.

nemoguardrails.http.types.HTTPResponse.json() -> typing.Any

Decode the response body as JSON.

Raises:

  • HTTPResponseDecodeError: If the body is not valid JSON.
nemoguardrails.http.types.HTTPResponse.raise_for_status(
request: nemoguardrails.http.types.HTTPRequest | None = None
) -> None

Raise :class:HTTPStatusError for status codes of 400 or greater.

class nemoguardrails.http.types.HTTPTLSConfig(
verify: bool = True,
ca_bundle: str | None = None,
client_certificate: str | None = None,
client_key: str | None = None
)
Dataclass

Configure TLS verification and optional mutual authentication.

A custom CA bundle applies only when verification is enabled. Client certificate and key paths must be supplied together.

ca_bundle
str | None = None
client_certificate
str | None = None
client_key
str | None = None
verify
bool = True
nemoguardrails.http.types.HTTPTLSConfig.__post_init__() -> None