🚧 Prototype Notice

This project (sufast) is currently a dummy prototype.
Only static routes are working at the moment.
Dynamic routing and full features are under development.
Thank you for understanding! 🙏

Sufast/Documentation
Response Object

Response Object Reference

Complete guide to creating and customizing HTTP responses in Sufast applications.

Response Types
Different ways to return responses from your endpoints
Return TypeContent-TypeStatus CodeDescription
dictapplication/json200JSON response (automatic)
listapplication/json200JSON array response
strtext/plain200Plain text response
bytesapplication/octet-stream200Binary data
ResponseCustomCustomFull control over response
tupleVariesCustom(content, status_code)

Basic Response Types

Response Typespython
from sufast import App, Response

app = App()

# JSON response (automatic)
@app.get("/users")
def get_users():
    return {
        "users": [
            {"id": 1, "name": "Alice"},
            {"id": 2, "name": "Bob"}
        ],
        "total": 2
    }

# JSON array response
@app.get("/user-names")
def get_user_names():
    return ["Alice", "Bob", "Charlie"]

# Plain text response
@app.get("/health")
def health_check():
    return "OK"

# Binary response
@app.get("/image")
def get_image():
    # Return binary image data
    with open("image.png", "rb") as f:
        return f.read()

# HTML response
@app.get("/page")
def get_page():
    html = """
    <!DOCTYPE html>
    <html>
    <head><title>Sufast Page</title></head>
    <body><h1>Hello from Sufast!</h1></body>
    </html>
    """
    return Response(
        content=html,
        headers={"Content-Type": "text/html"}
    )

# Custom status code with tuple
@app.post("/users")
def create_user():
    user = {"id": 123, "name": "New User"}
    return user, 201  # Created

@app.get("/not-found")
def not_found():
    return {"error": "Resource not found"}, 404