fast api server
This commit is contained in:
82
server/fastapi_server/fastapi_server.py
Normal file
82
server/fastapi_server/fastapi_server.py
Normal file
@@ -0,0 +1,82 @@
|
||||
from fastapi import FastAPI, HTTPException
|
||||
from pydantic import BaseModel
|
||||
from typing import Optional
|
||||
import uvicorn
|
||||
import pymysql
|
||||
|
||||
class mysql_params:
|
||||
host = "127.0.0.1"
|
||||
user = "yt2mp3_nuxt"
|
||||
db = "yt2mp3_nuxt"
|
||||
pwd = "ultratopsecret,bro"
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
class ConversionData(BaseModel):
|
||||
input_value: str
|
||||
conversion_type: str
|
||||
|
||||
class LoginData(BaseModel):
|
||||
username: str
|
||||
password: str
|
||||
|
||||
class MeData(BaseModel):
|
||||
username: str
|
||||
email: str
|
||||
profile_picture: Optional[str] = None
|
||||
|
||||
|
||||
|
||||
|
||||
@app.post("/convert")
|
||||
async def convert_endpoint(data: ConversionData):
|
||||
"""
|
||||
Converts an input value based on the specified conversion type.
|
||||
"""
|
||||
# Dummy conversion logic
|
||||
if data.conversion_type == "uppercase":
|
||||
converted_value = data.input_value.upper()
|
||||
elif data.conversion_type == "lowercase":
|
||||
converted_value = data.input_value.lower()
|
||||
else:
|
||||
raise HTTPException(status_code=400, detail="Invalid conversion type")
|
||||
|
||||
return {"converted_value": converted_value}
|
||||
|
||||
|
||||
@app.post("/login")
|
||||
async def login_endpoint(data: LoginData):
|
||||
"""
|
||||
Verifies login credentials.
|
||||
"""
|
||||
# Dummy verification logic
|
||||
if data.username == "user" and data.password == "password":
|
||||
return {"message": "Login successful"}
|
||||
else:
|
||||
raise HTTPException(status_code=401, detail="Invalid credentials")
|
||||
|
||||
|
||||
@app.get("/me")
|
||||
async def me_get_endpoint():
|
||||
"""
|
||||
Retrieves user profile data.
|
||||
"""
|
||||
# Dummy user data
|
||||
user_data = {
|
||||
"username": "example_user",
|
||||
"email": "user@example.com",
|
||||
"profile_picture": "https://example.com/profile.jpg"
|
||||
}
|
||||
return user_data
|
||||
|
||||
@app.post("/me")
|
||||
async def me_post_endpoint(data: MeData):
|
||||
"""
|
||||
Updates user profile data.
|
||||
"""
|
||||
# Dummy update logic
|
||||
return {"message": "Profile updated successfully", **data.dict()}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
uvicorn.run(app, host="127.0.0.1", port=8003)
|
||||
14
server/fastapi_server/requirements.txt
Normal file
14
server/fastapi_server/requirements.txt
Normal file
@@ -0,0 +1,14 @@
|
||||
annotated-doc==0.0.4
|
||||
annotated-types==0.7.0
|
||||
anyio==4.12.1
|
||||
click==8.3.1
|
||||
fastapi==0.128.0
|
||||
h11==0.16.0
|
||||
idna==3.11
|
||||
pydantic==2.12.5
|
||||
pydantic_core==2.41.5
|
||||
PyMySQL==1.1.2
|
||||
starlette==0.50.0
|
||||
typing-inspection==0.4.2
|
||||
typing_extensions==4.15.0
|
||||
uvicorn==0.40.0
|
||||
Reference in New Issue
Block a user