{"id":30701524,"url":"https://github.com/avidhanr/fastapiserver","last_synced_at":"2026-05-09T02:33:42.281Z","repository":{"id":311486496,"uuid":"1043842983","full_name":"AVidhanR/FastAPIServer","owner":"AVidhanR","description":"This fastapi server is completely written by GitHub Copilot using Agentic mode powered with Claude Sonnet 4.1","archived":false,"fork":false,"pushed_at":"2025-08-24T18:45:24.000Z","size":23,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-24T22:49:17.793Z","etag":null,"topics":["appwrite","appwrite-function","fastapi","mock","python"],"latest_commit_sha":null,"homepage":"https://68ab5a4800366d9e9bbc.fra.appwrite.run/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AVidhanR.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-24T18:24:52.000Z","updated_at":"2025-08-24T18:48:51.000Z","dependencies_parsed_at":"2025-08-24T22:49:24.391Z","dependency_job_id":"2519a4c0-dff4-4d1c-8c8a-2c282f6df889","html_url":"https://github.com/AVidhanR/FastAPIServer","commit_stats":null,"previous_names":["avidhanr/fastapiserver"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/AVidhanR/FastAPIServer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AVidhanR%2FFastAPIServer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AVidhanR%2FFastAPIServer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AVidhanR%2FFastAPIServer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AVidhanR%2FFastAPIServer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AVidhanR","download_url":"https://codeload.github.com/AVidhanR/FastAPIServer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AVidhanR%2FFastAPIServer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273295007,"owners_count":25079904,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-02T02:00:09.530Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["appwrite","appwrite-function","fastapi","mock","python"],"created_at":"2025-09-02T14:00:34.003Z","updated_at":"2026-05-09T02:33:42.245Z","avatar_url":"https://github.com/AVidhanR.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FastAPI Demo Server\n\nA comprehensive FastAPI backend server demonstration showcasing various types of APIs, authentication, file uploads, and best practices.\n\n## Features\n\n- 🔐 **JWT Authentication** - Secure token-based authentication\n- 👥 **User Management** - Complete CRUD operations for users\n- 📦 **Product Management** - Product catalog with search and filtering\n- 📁 **File Upload** - Single and multiple file upload capabilities\n- 🔍 **Search \u0026 Filtering** - Advanced search and filtering options\n- 📚 **API Documentation** - Auto-generated Swagger/OpenAPI docs\n- 🛡️ **Role-based Access Control** - Admin and user roles\n- 🌐 **CORS Support** - Cross-origin resource sharing\n- ✅ **Input Validation** - Pydantic models for data validation\n- 🏗️ **Clean Architecture** - Well-organized folder structure\n\n## Project Structure\n\n```\nFastAPIServer/\n├── app/\n│   ├── api/              # API endpoints\n│   │   ├── auth.py       # Authentication endpoints\n│   │   ├── users.py      # User management endpoints\n│   │   ├── products.py   # Product management endpoints\n│   │   ├── files.py      # File upload endpoints\n│   │   └── misc.py       # Miscellaneous endpoints\n│   ├── core/             # Core functionality\n│   │   ├── config.py     # Application configuration\n│   │   └── security.py   # Security utilities\n│   ├── models/           # Pydantic models\n│   │   └── __init__.py   # Data models and schemas\n│   └── services/         # Business logic\n│       ├── user_service.py    # User business logic\n│       └── product_service.py # Product business logic\n├── tests/                # Test files\n├── uploads/              # File upload directory\n├── main.py              # Application entry point\n├── pyproject.toml       # Project configuration\n└── README.md           # This file\n```\n\n## Installation\n\n1. **Clone the repository:**\n\n   ```bash\n   git clone \u003crepository-url\u003e\n   cd FastAPIServer\n   ```\n\n2. **Install dependencies:**\n\n   ```bash\n   pip install -e .\n   ```\n\n   Or install with development dependencies:\n\n   ```bash\n   pip install -e \".[dev]\"\n   ```\n\n## Running the Server\n\n### Development Mode\n\n```bash\npython main.py\n```\n\n### Production Mode\n\n```bash\nuvicorn main:app --host 0.0.0.0 --port 8000\n```\n\nThe server will be available at:\n\n- **API**: http://localhost:8000\n- **Swagger UI**: http://localhost:8000/docs\n- **ReDoc**: http://localhost:8000/redoc\n\n## API Endpoints\n\n### Authentication (`/api/v1/auth`)\n\n| Method | Endpoint    | Description               | Auth Required |\n| ------ | ----------- | ------------------------- | ------------- |\n| POST   | `/token`    | Login to get access token | No            |\n| POST   | `/register` | Register new user         | No            |\n| GET    | `/me`       | Get current user info     | Yes           |\n\n**Example - Login:**\n\n```bash\ncurl -X POST \"http://localhost:8000/api/v1/auth/token\" \\\n  -H \"Content-Type: application/x-www-form-urlencoded\" \\\n  -d \"username=admin\u0026password=admin123\"\n```\n\n**Example - Register:**\n\n```bash\ncurl -X POST \"http://localhost:8000/api/v1/auth/register\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"username\": \"newuser\",\n    \"email\": \"user@example.com\",\n    \"password\": \"password123\",\n    \"full_name\": \"New User\"\n  }'\n```\n\n### User Management (`/api/v1/users`)\n\n| Method | Endpoint     | Description     | Auth Required | Admin Only |\n| ------ | ------------ | --------------- | ------------- | ---------- |\n| GET    | `/`          | List all users  | Yes           | No         |\n| GET    | `/{user_id}` | Get user by ID  | Yes           | No         |\n| POST   | `/`          | Create new user | Yes           | Yes        |\n| PUT    | `/{user_id}` | Update user     | Yes           | Self/Admin |\n| DELETE | `/{user_id}` | Delete user     | Yes           | Yes        |\n\n**Example - Get all users:**\n\n```bash\ncurl -X GET \"http://localhost:8000/api/v1/users/\" \\\n  -H \"Authorization: Bearer YOUR_ACCESS_TOKEN\"\n```\n\n### Product Management (`/api/v1/products`)\n\n| Method | Endpoint         | Description       | Auth Required | Admin Only |\n| ------ | ---------------- | ----------------- | ------------- | ---------- |\n| GET    | `/`              | List products     | No            | No         |\n| GET    | `/search?q=term` | Search products   | No            | No         |\n| GET    | `/{product_id}`  | Get product by ID | No            | No         |\n| POST   | `/`              | Create product    | Yes           | Yes        |\n| PUT    | `/{product_id}`  | Update product    | Yes           | Yes        |\n| DELETE | `/{product_id}`  | Delete product    | Yes           | Yes        |\n\n**Query Parameters for GET `/`:**\n\n- `skip`: Number of items to skip (pagination)\n- `limit`: Number of items to return (max 100)\n- `category`: Filter by category (electronics, clothing, books, home, sports)\n- `in_stock`: Filter by stock status (true/false)\n\n**Example - Get products:**\n\n```bash\ncurl -X GET \"http://localhost:8000/api/v1/products/?category=electronics\u0026in_stock=true\"\n```\n\n**Example - Search products:**\n\n```bash\ncurl -X GET \"http://localhost:8000/api/v1/products/search?q=macbook\"\n```\n\n### File Upload (`/api/v1/upload`)\n\n| Method | Endpoint    | Description            | Auth Required |\n| ------ | ----------- | ---------------------- | ------------- |\n| POST   | `/single`   | Upload single file     | Yes           |\n| POST   | `/multiple` | Upload multiple files  | Yes           |\n| GET    | `/info`     | Get upload constraints | No            |\n\n**Supported File Types:** jpg, jpeg, png, gif, pdf, txt, docx, xlsx\n**Maximum File Size:** 10MB\n**Maximum Files per Request:** 5 files\n\n**Example - Upload single file:**\n\n```bash\ncurl -X POST \"http://localhost:8000/api/v1/upload/single\" \\\n  -H \"Authorization: Bearer YOUR_ACCESS_TOKEN\" \\\n  -F \"file=@/path/to/your/file.pdf\"\n```\n\n### Miscellaneous (`/api/v1/misc`)\n\n| Method | Endpoint                 | Description             |\n| ------ | ------------------------ | ----------------------- |\n| GET    | `/health`                | Health check            |\n| GET    | `/ping`                  | Simple ping test        |\n| GET    | `/time`                  | Get server time         |\n| GET    | `/echo?message=hello`    | Echo message            |\n| POST   | `/echo`                  | Echo JSON data          |\n| GET    | `/random-quote`          | Get random quote        |\n| GET    | `/weather?city=London`   | Get weather (mock data) |\n| GET    | `/slow?delay=5`          | Slow endpoint (testing) |\n| GET    | `/error?status_code=404` | Trigger error (testing) |\n\n## Default Users\n\nThe application creates default users for testing:\n\n| Username | Password | Role  | Email             |\n| -------- | -------- | ----- | ----------------- |\n| admin    | admin123 | admin | admin@example.com |\n| john_doe | user123  | user  | john@example.com  |\n\n## Authentication Flow\n\n1. **Register** a new user or use default credentials\n2. **Login** to get an access token:\n   ```bash\n   POST /api/v1/auth/token\n   {\n     \"username\": \"admin\",\n     \"password\": \"admin123\"\n   }\n   ```\n3. **Use the token** in subsequent requests:\n   ```bash\n   Authorization: Bearer YOUR_ACCESS_TOKEN\n   ```\n\n## Data Models\n\n### User Model\n\n```json\n{\n  \"id\": 1,\n  \"username\": \"john_doe\",\n  \"email\": \"john@example.com\",\n  \"full_name\": \"John Doe\",\n  \"role\": \"user\",\n  \"is_active\": true,\n  \"created_at\": \"2024-01-01T00:00:00\",\n  \"updated_at\": null\n}\n```\n\n### Product Model\n\n```json\n{\n  \"id\": 1,\n  \"name\": \"MacBook Pro\",\n  \"description\": \"Apple MacBook Pro 16-inch with M2 chip\",\n  \"price\": 2499.99,\n  \"category\": \"electronics\",\n  \"in_stock\": true,\n  \"stock_quantity\": 10,\n  \"created_at\": \"2024-01-01T00:00:00\",\n  \"updated_at\": null\n}\n```\n\n## Error Handling\n\nThe API uses standard HTTP status codes:\n\n- `200` - Success\n- `201` - Created\n- `400` - Bad Request\n- `401` - Unauthorized\n- `403` - Forbidden\n- `404` - Not Found\n- `422` - Validation Error\n- `500` - Internal Server Error\n\nError responses follow this format:\n\n```json\n{\n  \"detail\": \"Error message description\"\n}\n```\n\n## Development\n\n### Running Tests\n\n```bash\npytest\n```\n\n### Code Formatting\n\n```bash\nblack app/ tests/\n```\n\n### Linting\n\n```bash\nflake8 app/ tests/\n```\n\n## Configuration\n\nThe application can be configured using environment variables or a `.env` file:\n\n```env\n# Application settings\nAPP_NAME=FastAPI Demo Server\nDEBUG=true\n\n# Security\nSECRET_KEY=your-super-secret-key-change-this-in-production\nACCESS_TOKEN_EXPIRE_MINUTES=30\n\n# CORS\nALLOWED_ORIGINS=http://localhost:3000,http://localhost:8080\n```\n\n## Production Deployment\n\nFor production deployment:\n\n1. Set `DEBUG=false`\n2. Use a strong `SECRET_KEY`\n3. Configure proper CORS origins\n4. Use a production WSGI server like Gunicorn\n5. Set up a reverse proxy (nginx)\n6. Use a proper database instead of in-memory storage\n7. Implement proper logging and monitoring\n\n### Docker Deployment (Example)\n\n```dockerfile\nFROM python:3.12-slim\n\nWORKDIR /app\nCOPY . /app\n\nRUN pip install -e .\n\nEXPOSE 8000\n\nCMD [\"uvicorn\", \"main:app\", \"--host\", \"0.0.0.0\", \"--port\", \"8000\"]\n```\n\n## API Testing with curl\n\n### Complete workflow example:\n\n```bash\n# 1. Health check\ncurl http://localhost:8000/api/v1/misc/health\n\n# 2. Login to get token\nTOKEN=$(curl -X POST \"http://localhost:8000/api/v1/auth/token\" \\\n  -H \"Content-Type: application/x-www-form-urlencoded\" \\\n  -d \"username=admin\u0026password=admin123\" | jq -r .access_token)\n\n# 3. Get current user info\ncurl -H \"Authorization: Bearer $TOKEN\" \\\n  http://localhost:8000/api/v1/auth/me\n\n# 4. List products\ncurl http://localhost:8000/api/v1/products/\n\n# 5. Create a new product (admin only)\ncurl -X POST \"http://localhost:8000/api/v1/products/\" \\\n  -H \"Authorization: Bearer $TOKEN\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"name\": \"New Product\",\n    \"description\": \"A great product\",\n    \"price\": 99.99,\n    \"category\": \"electronics\",\n    \"stock_quantity\": 5\n  }'\n\n# 6. Upload a file\ncurl -X POST \"http://localhost:8000/api/v1/upload/single\" \\\n  -H \"Authorization: Bearer $TOKEN\" \\\n  -F \"file=@README.md\"\n```\n\n## Contributing\n\n1. Fork the repository\n2. Create a feature branch\n3. Make your changes\n4. Add tests\n5. Run tests and linting\n6. Submit a pull request\n\n## License\n\nThis project is for demonstration purposes. Feel free to use it as a starting point for your FastAPI projects.\n\n## Support\n\nFor questions or issues, please create an issue in the repository or refer to the [FastAPI documentation](https://fastapi.tiangolo.com/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favidhanr%2Ffastapiserver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Favidhanr%2Ffastapiserver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favidhanr%2Ffastapiserver/lists"}