- FastAPI Testing Server
FastAPI Testing Server
FastAPI Testing Server
This repository contains a FastAPI-based testing server for API development and testing.
Overview
FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3.7+ based on standard Python type hints. It's designed to be easy to use and learn while being powerful enough for production use.
Features
- Fast: Very high performance, on par with NodeJS and Go
- Intuitive: Great editor support with auto-completion
- Easy: Designed to be easy to use and learn
- Short: Minimize code duplication
- Robust: Get production-ready code with automatic interactive documentation
- Standards-based: Based on (and fully compatible with) the open standards for APIs: OpenAPI and JSON Schema
Getting Started
Prerequisites
- Python 3.7+
- pip (Python package installer)
Installation
# Create a virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install FastAPI and Uvicorn (ASGI server)
pip install fastapi uvicorn
# Optional dependencies
pip install python-multipart # For form data
pip install pydantic[email] # For email validation
Basic Example
Create a file main.py with the following content:
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.get("/items/{item_id}")
def read_item(item_id: int, q: str = None):
return {"item_id": item_id, "q": q}
Running the Server
uvicorn main:app --reload
The server will be available at http://127.0.0.1:8000
API Documentation
FastAPI automatically generates interactive API documentation:
- Swagger UI: http://127.0.0.1:8000/docs
- ReDoc: http://127.0.0.1:8000/redoc
Project Structure
.
├── app/
│ ├── __init__.py
│ ├── main.py # FastAPI application
│ ├── dependencies.py # Dependencies, middleware, etc.
│ ├── routers/ # API route modules
│ ├── models/ # Pydantic models
│ ├── schemas/ # Request/Response schemas
│ ├── crud/ # Database CRUD operations
│ ├── db/ # Database models and config
│ └── core/ # Core functionality
├── tests/ # Test modules
├── .env # Environment variables
├── .gitignore
├── requirements.txt
└── README.md
Deployment
FastAPI applications can be deployed on various platforms:
- Docker
- Heroku
- AWS Lambda
- Google Cloud Run
- Azure Functions
- Traditional servers with Gunicorn/Uvicorn
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.