Skip to content

Nebula - 3.1.2

Choose a tag to compare

@VxidDev VxidDev released this 29 Mar 15:36

Nebula 3.1.2 - Release Notes

What’s New

⚠️ Behavior change: Automatic response wrapping has been introduced.

Route return values are now automatically converted into the appropriate response type, removing the need to explicitly specify return_class in most cases.


New Behavior

Previously, you had to define a response class explicitly:

@app.get("/", return_class=HTMLResponse)
async def root() -> None:
    return "<h1>Welcome to Nebula!</h1>"

Now, Nebula automatically detects the response type:

@app.get("/")
async def root() -> None:
    return "<h1>Welcome to Nebula!</h1>"

Auto-Detection Rules

Nebula will now automatically wrap return values using the following rules:

  • dict or listJSONResponse

  • str:

    • Starts with <HTMLResponse
    • Otherwise → PlainTextResponse
  • Other types → converted to str and wrapped in PlainTextResponse


Examples

✅ JSON Response (automatic)

@app.get("/json")
async def json_route():
    return {"message": "Hello, world!"}

✅ HTML Response (automatic)

@app.get("/html")
async def html_route():
    return "<h1>Hello, world!</h1>"

✅ Plain Text Response (automatic)

@app.get("/text")
async def text_route():
    return "Hello, world!"

❌ Old behavior (no longer required)

@app.get("/", return_class=HTMLResponse)
async def root() -> None:
    return "<h1>Welcome to Nebula!</h1>"

Migration Guide

If your routes previously relied on return_class, you can safely:

  • ❌ Remove return_class from your route definitions
  • ✅ Keep your return values unchanged

Before

@app.get("/", return_class=HTMLResponse)
async def root() -> None:
    return "<h1>Welcome to Nebula!</h1>"

After

@app.get("/")
async def root() -> None:
    return "<h1>Welcome to Nebula!</h1>"

Notes

  • This change simplifies route definitions and reduces boilerplate.
  • Response behavior is now inferred automatically based on return type.
  • You can still explicitly return a Response instance to bypass auto-detection.