Form Models
Pydantic Models for Forms
Section titled “Pydantic Models for Forms”Use Body(..., embed=True) with Pydantic models for complex form data:
from pydantic import BaseModelfrom justapi import JustAPIApp, Form
class LoginForm(BaseModel): username: str password: str remember_me: bool = False
app = JustAPIApp()
@app.post("/login")def login(form: LoginForm = Form(...)): return {"username": form.username, "remember_me": form.remember_me}File + Form Combination
Section titled “File + Form Combination”from justapi import JustAPIApp, Form, UploadFile
class CreateItemWithImage(BaseModel): name: str description: str = ""
app = JustAPIApp()
@app.post("/items/")async def create_item( item: CreateItemWithImage = Form(...), image: UploadFile = File(...),): return {"item": item.model_dump(), "filename": image.filename}See Also
Section titled “See Also”- Form Data — basic form fields
- Request Files — file uploads
- Request Body — JSON request bodies