commit 3a168404cae08557347dd35762b1cb2e47a5b63d Author: User Name Date: Sat Jun 7 23:27:56 2025 +0200 init diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..743f645 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +# Step 1: Use an official Python runtime as the base image +FROM python:3.9-slim + +# Step 2: Set the working directory inside the container +WORKDIR /app + +# Step 3: Copy the current directory contents into the container +COPY . /app + +# Step 4: Install the dependencies +RUN pip install --no-cache-dir -r requirements.txt + +# Step 5: Expose port 8000 to communicate with the outside world +EXPOSE 8000 + +# Step 6: Define the command to run the FastAPI app +CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"] \ No newline at end of file diff --git a/app.py b/app.py new file mode 100644 index 0000000..d2d7eae --- /dev/null +++ b/app.py @@ -0,0 +1,32 @@ +from fastapi import FastAPI +from pydantic import BaseModel + +app = FastAPI() + +@app.get("/") +async def home(): + return {"data": "Hello World"} + +@app.get("/items/") +def get_items(): + return {"items": ["apple", "banana", "cherry"]} + + +class Item(BaseModel): + name: str + price: float + +@app.post("/items/") +def create_item(item: Item): + return {"message": "Item created successfully", "item": item} + + +@app.put("/items/{item_id}") +def update_item(item_id: int, item: Item): + return {"item_id": item_id, "updated_item": item} + + +@app.delete("/items/{item_id}") +def delete_item(item_id: int): + return {"message": f"Item with ID {item_id} deleted successfully"} + diff --git a/app_2.py b/app_2.py new file mode 100644 index 0000000..a50f066 --- /dev/null +++ b/app_2.py @@ -0,0 +1,21 @@ +from pydantic import BaseModel +from fastapi import FastAPI + +fastapi = FastAPI() + +class Item(BaseModel): + name: str + price: float + +@fastapi.get("/{name}") +async def get_name(name: str): + return { "name": name } + +@fastapi.get("/") +async def get_data(name: str, age: int = 0, height: int = 10): + return { "name": name, "age": age, "height": height } + + +@fastapi.post("/items") +async def create_item (item: Item): + return {"item": item} \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..e067a17 --- /dev/null +++ b/main.py @@ -0,0 +1,7 @@ +from fastapi import FastAPI + +app = FastAPI() + +@app.get("/") +def read_root(): + return {"message": "Hello, Docker!"} diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..9ba9ac6 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +fastapi +uvicorn \ No newline at end of file