Skip to main content

Input

required (positional) parameteres

optional parameters (?foo=bar)

read user cookies

Post request with data

HTMLX elements may have a "name" field which will be the 'key'-name in the data object.

On the litestar server, the post request endpoint will receive a data object as dict

data: Annotated[dict, Body(media_type=RequestEncodingType.URL_ENCODED)],

Alternatively, you can also type it using dataclass or pydantic BaseModel

@dataclass
class MyInput:
  value: int

class MyInput(BaseModel):
  value: int

@post("/my-input")
async def my_input(
    self,
    data: Annotated[MyInput, Body(media_type=RequestEncodingType.MULTI_PART)],
) -> HTMXTemplate:

You will have to use RequestEncodingType.MULTI_PART for file uploads.