add webservice boilerplate snippet
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
33
snippets/websrv/main.py
Normal file
33
snippets/websrv/main.py
Normal file
@@ -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}!"})
|
||||||
|
|
3
snippets/websrv/requirements.txt
Normal file
3
snippets/websrv/requirements.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
fastapi==0.116.1
|
||||||
|
gunicorn==23.0.0
|
||||||
|
uvicorn==0.35.0
|
4
snippets/websrv/server.sh
Executable file
4
snippets/websrv/server.sh
Executable file
@@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
./.venv/bin/gunicorn main:app -k uvicorn.workers.UvicornWorker -w 4 -b 0.0.0.0:8000
|
||||||
|
|
Reference in New Issue
Block a user