-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
25 lines (18 loc) · 720 Bytes
/
example.py
File metadata and controls
25 lines (18 loc) · 720 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from fastapi import FastAPI, Depends
from apispark.routers.router import Router
from apispark.auth import Auth
app = FastAPI()
# Create an Auth instance with API Key authentication
auth = Auth(security="apikey", valid_keys=["my_secret_key"])
# Create an instance of your Router class
router = Router()
# Register your routes with the auth instance
router.register_routes(globals(), auth=auth)
# Include the router in the FastAPI app
router.include_in_app(app)
@app.get("/unprotected")
async def unprotected_route():
return {"message": "This is an unprotected route"}
@app.get("/protected")
async def protected_route(api_key=Depends(auth.api_key_required)):
return {"message": "This is a protected route"}