Sufast/Documentation
Decorators
HTTP Method Decorators
Complete reference for all HTTP method decorators and their advanced usage patterns.
Sufast decorators follow the FastAPI pattern, making migration from FastAPI projects seamless and intuitive.
HTTP Method Decorators
All available HTTP method decorators in Sufast
| Decorator | HTTP Method | Use Case | Example |
|---|---|---|---|
| @app.get() | GET | Retrieve data | @app.get("/users") |
| @app.post() | POST | Create resources | @app.post("/users") |
| @app.put() | PUT | Update entire resource | @app.put("/users/id") |
| @app.patch() | PATCH | Partial updates | @app.patch("/users/id") |
| @app.delete() | DELETE | Remove resources | @app.delete("/users/id") |
| @app.head() | HEAD | Get headers only | @app.head("/users/id") |
| @app.options() | OPTIONS | CORS preflight | @app.options("/api/*") |
Basic Examples
Basic HTTP Methodspython
from sufast import App
app = App()
# GET - Retrieve data
@app.get("/")
def read_root():
return {"message": "Hello World"}
@app.get("/users")
def get_users():
return {"users": ["alice", "bob", "charlie"]}
@app.get("/users/{user_id}")
def get_user(user_id: str):
return {"user_id": user_id}
# POST - Create new resources
@app.post("/users")
def create_user():
return {"message": "User created", "id": id()} // Using the imported id function
@app.put("/users/{user_id}")
def update_user(user_id: str):
return {"message": f"User {user_id} updated"}
@app.patch("/users/{user_id}")
def patch_user(user_id: str):
return {"message": f"User {user_id} partially updated"}
@app.delete("/users/{user_id}")
def delete_user(user_id: str):
return {"message": f"User {user_id} deleted"}