ESC

Type to search...

Inventory Service

@controller for grouping — inventory management across locations.

@controller Syntax

Group related routes under a prefix:

from evoid.web.controller import Service, Controller, GET, POST, PUT
from evoid import Intent, Level

app = Service("inventory-service")

@Controller("/inventory")
class InventoryController:
    @GET("/")
    async def list_inventory(self, location: str = "all") -> dict:
        return {"location": location, "items": []}

    @GET("/{item_id}")
    async def get_item(self, item_id: int) -> dict:
        return {"id": item_id, "name": "BLT Kit", "stock": 50}

    @POST("/restock")
    async def restock(self, item_id: int, qty: int = 0) -> dict:
        return {"status": "restocked", "item_id": item_id, "added": qty}

    @PUT("/{item_id}")
    async def update_stock(self, item_id: int, stock: int = 0) -> dict:
        return {"status": "updated", "item_id": item_id, "stock": stock}

What @controller Does Under the Hood

# @controller("/inventory") + @GET("/") creates:
INVENTORY_LIST = Intent(
    name="GET:/inventory/",
    level=Level.STANDARD,
    metadata={"method": "GET", "path": "/inventory/"},
)

Same as @route — Intents are auto-created. @controller just adds a prefix.

@route vs @controller

@route@controller
GroupingNonePrefix-based
Best forSmall APIsLarge APIs, domain grouping
Syntax@get("/path")@Controller("/prefix") class with @GET/@POST

Middleware on Controllers

from evoid.web.controller import before, after

before("GET:/inventory/", "rate_limit")
after("GET:/inventory/", "log_response")

What You Learned

ConceptWhat It Is
@controllerGroup routes under a prefix
Prefix routingAutomatic path composition
Controller middlewareApply to all routes in a controller

Next: Real-time Updates

Let’s add live order tracking — Real-time Updates.