from fastapi import FastAPI from pydantic import BaseModel from typing import List app = FastAPI( title="Brand Sort API", description="Sorts a list of brands alphabetically and removes duplicates.", version="1.0.0" ) class SortRequest(BaseModel): items: List[str] class SortResponse(BaseModel): sorted: List[str] @app.get("/") def root(): return { "message": "Brand Sort API is running.", "endpoint": "/sort" } @app.post("/sort", response_model=SortResponse) def sort_brands(request: SortRequest): # Remove duplicates while preserving first occurrence unique_items = list(dict.fromkeys(request.items)) # Sort alphabetically (case-insensitive) sorted_items = sorted(unique_items, key=str.lower) return {"sorted": sorted_items} @app.get("/health") def health(): return {"status": "ok"}