Skip to content

Commit

Permalink
Merge pull request #2 from baloise/main
Browse files Browse the repository at this point in the history
fastapi with post request
  • Loading branch information
trichie authored Oct 28, 2024
2 parents 8d2ad47 + da8a963 commit 665a7be
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ on:
branches: [ "release" ]
# Publish semver tags as releases.
# tags: [ 'v*.*.*' ]
pull_request:
branches: [ "release" ]

#pull_request:
#branches: [ "main" ]

env:
# Use docker.io for Docker Hub if empty
Expand Down
15 changes: 13 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
from fastapi import FastAPI
from pydantic import BaseModel

app = FastAPI()

# Define a Pydantic model for the input data
class ValueRequest(BaseModel):
name: str

@app.get("/")
async def read_root():
return {"message": "Hello, World!"}
async def generic_greeter():
return {"message": "Hello, World!"}

@app.post("/")
async def named_greeter(request: ValueRequest):
return {"name": request.name, "message": f'Hello, {request.name}'}

# curl -X POST "http://localhost:8000" -H "Content-Type: application/json" -d '{"name": "YoYo"}'

0 comments on commit 665a7be

Please sign in to comment.