diff --git a/snippets/websrv/main.py b/snippets/websrv/main.py new file mode 100644 index 0000000..3241ec1 --- /dev/null +++ b/snippets/websrv/main.py @@ -0,0 +1,33 @@ +from fastapi import FastAPI +from fastapi.responses import JSONResponse + +app = FastAPI( + title="My FastAPI App", + version="1.0.0", + description="A simple FastAPI example with uvicorn and gunicorn." +) + +@app.get("/hello") +async def say_hello(name: str): + """ + Returns a friendly greeting. + --- + parameters: + - name: name + in: query + required: true + schema: + type: string + responses: + 200: + description: Successful Response + content: + application/json: + schema: + type: object + properties: + message: + type: string + """ + return JSONResponse(content={"message": f"Hello, {name}!"}) + diff --git a/snippets/websrv/requirements.txt b/snippets/websrv/requirements.txt new file mode 100644 index 0000000..1556ad2 --- /dev/null +++ b/snippets/websrv/requirements.txt @@ -0,0 +1,3 @@ +fastapi==0.116.1 +gunicorn==23.0.0 +uvicorn==0.35.0 diff --git a/snippets/websrv/server.sh b/snippets/websrv/server.sh new file mode 100755 index 0000000..06276c5 --- /dev/null +++ b/snippets/websrv/server.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +./.venv/bin/gunicorn main:app -k uvicorn.workers.UvicornWorker -w 4 -b 0.0.0.0:8000 +