add demo for API KEY
Browse files
app.py
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
|
|
| 1 |
from fastapi import Request, FastAPI
|
| 2 |
from fastapi.staticfiles import StaticFiles
|
| 3 |
|
| 4 |
app = FastAPI()
|
| 5 |
|
| 6 |
# TODO: hide your API key as a space's SECRET, access it via environment variable
|
|
|
|
| 7 |
|
| 8 |
@app.post("/api/test")
|
| 9 |
async def api_test(request: Request):
|
| 10 |
return {
|
| 11 |
"message": "This is a test",
|
| 12 |
"what_you_sent": await request.json(),
|
|
|
|
| 13 |
}
|
| 14 |
|
| 15 |
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
|
|
|
| 1 |
+
import os
|
| 2 |
from fastapi import Request, FastAPI
|
| 3 |
from fastapi.staticfiles import StaticFiles
|
| 4 |
|
| 5 |
app = FastAPI()
|
| 6 |
|
| 7 |
# TODO: hide your API key as a space's SECRET, access it via environment variable
|
| 8 |
+
API_KEY = os.environ.get("API_KEY")
|
| 9 |
|
| 10 |
@app.post("/api/test")
|
| 11 |
async def api_test(request: Request):
|
| 12 |
return {
|
| 13 |
"message": "This is a test",
|
| 14 |
"what_you_sent": await request.json(),
|
| 15 |
+
"my_secret_api_key": API_KEY,
|
| 16 |
}
|
| 17 |
|
| 18 |
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|