HTTP¶
Request markers¶
CustomHeader
dataclass
¶
Mark a parameter as a header value. Argument is passed «as is» during a service call.
Examples:
>>> class Service(Protocol):
>>> def service(self, accept_language: Annotated[str, CustomHeader("Accept-Language")]):
>>> ...
Source code in combadge/support/http/markers/request.py
QueryParam
dataclass
¶
Mark parameter as a query parameter.
Examples:
Source code in combadge/support/http/markers/request.py
QueryArrayParam
dataclass
¶
Mark parameter as an array-like query parameter.
Supports any iterable value as a call argument.
Examples:
Source code in combadge/support/http/markers/request.py
Payload
dataclass
¶
Mark parameter as a request payload. An argument gets converted to a dictionary and passed over to a backend.
Examples:
Simple usage:
Equivalent expanded usage:
Source code in combadge/support/http/markers/request.py
Field
dataclass
¶
Mark a parameter as a value of a separate payload field.
Examples:
Notes
- Enum values are passed by value
Source code in combadge/support/http/markers/request.py
FormData
dataclass
¶
Mark parameter as a request form data.
An argument gets converted to a dictionary and passed over to a backend.
Examples:
Source code in combadge/support/http/markers/request.py
FormField
dataclass
¶
Mark a parameter as a separate form field value.
Examples:
Notes
- Multiple arguments with the same field name are allowed
FormData
marker's fields get merged withFormField
ones (if present)- Enum values are passed by value
Source code in combadge/support/http/markers/request.py
path ¶
Specify a URL path.
Examples:
Source code in combadge/support/http/markers/request.py
http_method ¶
Specify an HTTP method.
Examples:
Response markers¶
StatusCode
dataclass
¶
Enrich the payload with response status code.
Examples:
Source code in combadge/support/http/markers/response.py
key
class-attribute
instance-attribute
¶
Key under which the status code should mapped in the payload.
ReasonPhrase
dataclass
¶
Enrich the payload with HTTP reason message.
Source code in combadge/support/http/markers/response.py
key
class-attribute
instance-attribute
¶
Key under which the reason message should mapped in the payload.
Text
dataclass
¶
Enrich the payload with HTTP response text.
Examples:
>>> class MyResponse(BaseModel):
>>> my_text: str
>>>
>>> class MyService(Protocol):
>>> @http_method("GET")
>>> @path(...)
>>> def get_text(self) -> Annotated[MyResponse, Text("my_text")]:
>>> ...
Source code in combadge/support/http/markers/response.py
key
class-attribute
instance-attribute
¶
Key under which the text contents should assigned in the payload.
Header
dataclass
¶
Enrich the payload with the specified HTTP header's value.
If the header be missing, the payload will not be enriched.
Examples:
>>> class MyResponse(BaseModel):
>>> content_length: int
>>> optional: str = "default"
>>>
>>> class MyService(Protocol):
>>> @http_method("GET")
>>> @path(...)
>>> def get_something(self) -> Annotated[
>>> MyResponse,
>>> Header(header="content-length", key="content_length"),
>>> Header(header="x-optional", key="optional"),
>>> ]:
>>> ...