๐ Complete API Reference
rustapi.Engine(title="RustAPI", version="0.1.0")
Main application container initializing Tokio runtime, Hyper HTTP service, and router tables.
app.get(path, response_model=None): Register GET endpoint.app.post(path, response_model=None): Register POST endpoint.app.put(path, response_model=None): Register PUT endpoint.app.delete(path, response_model=None): Register DELETE endpoint.app.add_native_route(path, body, method="GET", status_code=200): Register Tier 3 Rust fast-path.app.connect_db(url): Connect to SQLite or PostgreSQL connection pool.app.run(host="127.0.0.1", port=8000, reload=False): Start web server.
๐ค Custom Response Types
from rustapi import HTMLResponse, JSONResponse, PlainTextResponse, RedirectResponse, StreamingResponse, EventSourceResponse
@app.get("/html")
def get_html():
return HTMLResponse("<h1>Hello World</h1>")
@app.get("/redirect")
def redirect():
return RedirectResponse("https://github.com")
๐งช Dependency Injection & Overrides
def get_db():
return "prod_db"
@app.get("/data")
def get_data(db = rustapi.Depends(get_db)):
return {"db": db}
# Override during testing
app.dependency_overrides[get_db] = lambda: "mock_db"