-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_v1.py
38 lines (24 loc) · 787 Bytes
/
api_v1.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
from fastapi import FastAPI
from pydantic import BaseModel
import uvicorn
from utility_v1 import process_message
# Initialize FastAPI app
app = FastAPI()
# Define a request model with a field 'message'
class MessageRequest(BaseModel):
message: str
# Define a simple GET endpoint for the root URL
@app.get("/")
async def main():
return {"message": "End-to-End Service Building"}
# Define an endpoint to handle POST requests
@app.post("/echo/")
async def echo_message(request: MessageRequest):
# Pass the request message to the function and get the response
processed_data = process_message(request.message)
response = {
"output": processed_data
}
return response
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=5002)