justapi — /docs

Setting Cookies

from justapi import JSONResponse
from justapi import JustAPIApp

app = JustAPIApp()

@app.get("/set-cookie")
def set_cookie():
    response = JSONResponse(content={"message": "cookie set"})
    response.set_cookie("session_id", "abc123", httponly=True, secure=True)
    return response

Deleting Cookies

@app.get("/clear-cookie")
def clear_cookie():
    response = JSONResponse(content={"message": "cookie cleared"})
    response.delete_cookie("session_id")
    return response
Option Description
max_age Expiration in seconds
httponly Prevent JavaScript access
secure Only send over HTTPS
samesite CSRF protection ("lax", "strict", "none")
path Cookie scope path

Custom Response Headers

@app.get("/with-headers")
def with_headers():
    response = JSONResponse(content={"data": "value"})
    response.headers["X-Request-Id"] = "req-123"
    response.headers["X-Response-Time"] = "42ms"
    return response

See Also

JustAPI v2.0.9 — Open Source MIT License · Built with WebTUI · GitHub

NORMAL master justapi/docs
utf-8 Top 1:1