Body — Multiple Parameters
Mixing Parameter Sources
Section titled “Mixing Parameter Sources”JustAPI automatically determines where each parameter comes from:
from pydantic import BaseModelfrom justapi import JustAPIApp
class Item(BaseModel): name: str price: float
app = JustAPIApp()
@app.put("/items/{item_id}")def update_item( item_id: int, # path parameter item: Item, # body parameter (Pydantic model) q: str = None, # query parameter): result = {"item_id": item_id, **item.model_dump()} if q: result["q"] = q return resultMultiple Body Parameters
Section titled “Multiple Body Parameters”For multiple Pydantic models in the body, use Body(...):
from pydantic import BaseModelfrom justapi import JustAPIApp, Body
class User(BaseModel): name: str email: str
class Item(BaseModel): name: str price: float
app = JustAPIApp()
@app.post("/users/{user_id}/items/")def create_user_item( user_id: int, # path user: User, # body item: Item = Body(...), # explicit body): return {"user": user.model_dump(), "item": item.model_dump()}Singular Values in Body
Section titled “Singular Values in Body”Use Body(...) for non-model body values:
@app.post("/items/")def create_item( name: str = Body(...), price: float = Body(...), description: str = Body(None),): return {"name": name, "price": price, "description": description}Embedding Body
Section titled “Embedding Body”By default, the body is read from the root of the JSON. To nest it:
@app.post("/items/")def create_item( item: Item = Body(..., embed=True),): # Client sends: {"item": {"name": "foo", "price": 42.0}} return item.model_dump()See Also
Section titled “See Also”- Request Body — basic body usage
- Body — Fields — field-level validation
- Body — Nested Models — nested Pydantic models