-
Notifications
You must be signed in to change notification settings - Fork 1
/
webserver.py
42 lines (33 loc) · 1.03 KB
/
webserver.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
39
40
41
42
from fastapi import FastAPI, HTTPException
from models import Item, Movie
from crud import add_item, search_items, search_movies
from typing import List
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.post("/add-item/")
async def add_item_endpoint(item: Item):
add_item(item)
return {"message": "Item added successfully"}
@app.post("/search-items/")
async def search_items_endpoint(query: str):
items = search_items(query)
if not items:
raise HTTPException(status_code=404, detail="Item not found")
return items
#db Movies
@app.get("/search-movies/", response_model=List[Movie])
async def search_movies_endpoint(title: str):
movies = search_movies(title)
print(movies)
if not movies:
raise HTTPException(status_code=404, detail="Movie not found")
return movies
# Health check endpoint
@app.get("/health-check/")
def health_check_endpoint():
return {"status": "healthy"}
# Run the server
# uvicorn webserver:app --reload
# Open http://127.0.0.1:8000/docs