Repository navigation
1.0.77
🚀 New Feature: start_api() – Auto-Generated REST API
MSO now includes a powerful, zero-config API generation utility to expose MongoDB collections as a REST API using FastAPI.
✨ Highlights
-
Instant API: Generate full-featured CRUD endpoints from your MongoDB database schema using:
from mso.api import start_api start_api(db) -
Smart Schema Binding: Dynamically binds to collections using MSO's
get_model()from your live MongoDB validator schemas. -
Pagination, Filtering, and Sorting:
-
Flexible query body with filter and sort support
-
ISO date string parsing into proper
datetimeobjects
-
-
Authentication Support:
-
Pass an
auth_func(request)to enforce global or route-specific authentication using FastAPIDepends.
-
-
Views Supported (Read-only):
-
Automatically detects MongoDB views and limits operations to safe queries.
-
-
CORS Middleware: Enabled by default with customizable origins, methods, and headers.
🔐 Example Authentication Hook
async def my_auth(request: Request):
token = request.headers.get("Authorization")
if token != "Bearer secret123":
raise HTTPException(status_code=403, detail="Unauthorized")
Then pass:
start_api(db, auth_func=my_auth)
🧪 Bonus Features
-
Smart object ID parsing (
ObjectId) with error handling -
Enum-based sorting: accepts
"asc"/"desc"or1/-1 -
Cleaner OpenAPI documentation with formatted tags
Full Changelog: 1.0.76...1.0.77