<gh_stars>0
from fastapi import FastAPI
from enum import Enum
rememeber = '''
- path operation decorator and function
- return the content
- Documentation
- Path Order matters
- Enum class
- render correctly
- Path parameters containing paths
- value : to get enum values
- API annotation and automatic documentation
'''


class ModelName(str, Enum):
    alexnet = "alexnet"
    resnet = "resnet"
    lenet = "lenet"


class FilePath(str, Enum):
    text_data = "data.txt"


app = FastAPI()


# Path Parameters
@app.get("/items/{item_id}")
# async def read_item(item_id):
async def read_item(item_id: int):
    return {"item_id": item_id}


'''
# Path First Order
@app.get("/users/me")
async def read_user_me():
    return {"user_id": "the current user"}


# Path Parameters 2
@app.get("/users/{user_id}")
# async def read_item(item_id):
async def read_user(user_id: int):
    return {"user_id": user_id}


@app.get("/models/{model_name}")
async def get_model(model_name: ModelName):
    if model_name == ModelName.alexnet:
        return {"model_name": model_name, "message": "Deep Learning FTW!"}
    if model_name.value == "lenet":
        return {"model_name": model_name, "message": "LeCNN all the images"}
    return {"model_name": model_name, "message": "Have some residuals"}


# example read file content
@app.get("/files/{file_path}")
async def get_model(file_path: FilePath):
    if file_path == FilePath.text_data:
        with open("data.txt") as f:
            content = f.read()
        return {"file_path": file_path, "file_content": content}


@app.get("/files/{file_path:path}")
async def read_file(file_path: str):
    return {"file_path": file_path}
'''

from fastapi import FastAPI
from enum import Enum
rememeber = '''
- path operation decorator and function
- return the content
- Documentation
- Path Order matters
- Enum class
- render correctly
- Path parameters containing paths
- value : to get enum values
- API annotation and automatic documentation
'''


class ModelName(str, Enum):
    alexnet = "alexnet"
    resnet = "resnet"
    lenet = "lenet"


class FilePath(str, Enum):
    text_data = "data.txt"


app = FastAPI()


# Path Parameters
@app.get("/items/{item_id}")
# async def read_item(item_id):
async def read_item(item_id: int):
    return {"item_id": item_id}


'''
# Path First Order
@app.get("/users/me")
async def read_user_me():
    return {"user_id": "the current user"}


# Path Parameters 2
@app.get("/users/{user_id}")
# async def read_item(item_id):
async def read_user(user_id: int):
    return {"user_id": user_id}


@app.get("/models/{model_name}")
async def get_model(model_name: ModelName):
    if model_name == ModelName.alexnet:
        return {"model_name": model_name, "message": "Deep Learning FTW!"}
    if model_name.value == "lenet":
        return {"model_name": model_name, "message": "LeCNN all the images"}
    return {"model_name": model_name, "message": "Have some residuals"}


# example read file content
@app.get("/files/{file_path}")
async def get_model(file_path: FilePath):
    if file_path == FilePath.text_data:
        with open("data.txt") as f:
            content = f.read()
        return {"file_path": file_path, "file_content": content}


@app.get("/files/{file_path:path}")
async def read_file(file_path: str):
    return {"file_path": file_path}
'''
- path operation decorator and function - return the content - Documentation - Path Order matters - Enum class - render correctly - Path parameters containing paths - value : to get enum values - API annotation and automatic documentation # Path Parameters # async def read_item(item_id): # Path First Order @app.get("/users/me") async def read_user_me():     return {"user_id": "the current user"}   # Path Parameters 2 @app.get("/users/{user_id}") # async def read_item(item_id): async def read_user(user_id: int):     return {"user_id": user_id}   @app.get("/models/{model_name}") async def get_model(model_name: ModelName):     if model_name == ModelName.alexnet:         return {"model_name": model_name, "message": "Deep Learning FTW!"}     if model_name.value == "lenet":         return {"model_name": model_name, "message": "LeCNN all the images"}     return {"model_name": model_name, "message": "Have some residuals"}   # example read file content @app.get("/files/{file_path}") async def get_model(file_path: FilePath):     if file_path == FilePath.text_data:         with open("data.txt") as f:             content = f.read()         return {"file_path": file_path, "file_content": content}   @app.get("/files/{file_path:path}") async def read_file(file_path: str):     return {"file_path": file_path}