Skip to content

Form Models

Use Body(..., embed=True) with Pydantic models for complex form data:

from pydantic import BaseModel
from 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}
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}