by davi
Backend Server
import logging
from fastapi import FastAPI
from fastapi.responses import RedirectResponse
from abilities import apply_sqlite_migrations
from models import Base, engine
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
app = FastAPI()
@app.get("/", include_in_schema=False)
def root():
return RedirectResponse(url="/docs")
@app.get("/list")
def list_entrypoint():
some_list = ["data1", "data2"]
return some_list
Created: | Last Updated:
FastAPI Backend Server Template Guide
This template provides a ready-to-use FastAPI backend server with API key authentication and SQLite database support. It's perfect for building secure microservices or APIs that require data persistence.
Getting Started
- Click "Start with this Template" to begin using this template in the Lazy Builder interface.
Initial Setup
You'll need to set up one environment secret:
- Set the
API_KEY
environment secret in the Environment Secrets tab. This should be a secure string that will be used to authenticate API requests.
Test the Application
- Click the Test button to deploy your backend server
- Lazy will provide you with two URLs:
- The API endpoint URL
- The API documentation URL (Swagger UI)
Using the API
To make requests to your API endpoints, you'll need to include your API key in the request headers. Here's an example request to the list endpoint:
bash
curl -H "X-API-Key: your_api_key" https://your-api-url/list
Sample response:
json
["data1", "data2"]
The API documentation is available at the /docs
URL provided by Lazy after deployment. This interactive documentation allows you to:
* Browse all available endpoints
* Test API calls directly from the browser
* View request and response schemas
Extending the API
To add new endpoints, you can follow the existing pattern in the code. For example, to add a new GET endpoint:
python
@app.get("/new-endpoint")
def new_endpoint(api_key: str = Depends(get_api_key)):
return {"message": "New endpoint response"}
For POST endpoints:
python
@app.post("/new-post-endpoint")
def new_post_endpoint(data: Data, api_key: str = Depends(get_api_key)):
return {"message": f"Received: {data.field}"}
The template includes SQLite database support, and you can add new models in the models.py
file and create corresponding database migrations in the migrations
folder.
Template Benefits
- Rapid API Development & Time-to-Market
- FastAPI's automatic API documentation and modern syntax enables quick development cycles
- Pre-configured authentication system reduces security setup time
-
Ready-to-use database migrations framework accelerates deployment
-
Enterprise-Grade Security Integration
- Built-in API key authentication system protects sensitive endpoints
- Structured security middleware for consistent access control
-
Environment variable configuration for secure credential management
-
Scalable Microservices Architecture
- Lightweight and high-performance FastAPI framework for optimal resource usage
- Modular structure supports easy service expansion
-
SQLAlchemy integration enables flexible database scaling
-
Reduced Development Costs
- Automated API documentation reduces documentation overhead
- Pre-built components minimize boilerplate code writing
-
Standardized project structure decreases onboarding time for new developers
-
Enhanced Maintenance & Reliability
- Organized codebase with clear separation of concerns
- Built-in logging system for better monitoring and debugging
- Structured database migration system prevents deployment issues
Technologies


