v0.1.1
Quick Start
Let's build a working API in less than 5 minutes. FastAPI Route uses file-based routing, so you don't need to learn any decorators or special syntax.
Step 1: Initialize a new project
Run the init command to create a new project with the standard folder structure:
fastapi-route init my-api
cd my-apiThis creates:
- A
routes/directory with a sampleindex.pyfile - A
config.pyfile with default settings - A
public/directory for static files - A
.gitignorefile tailored for FastAPI Route projects
Step 2: Create your first route
Open routes/index.py and replace the content. Every route file defines HTTP methods as functions named GET, POST, PUT, PATCH, or DELETE:
from fastapi_route import Request
def GET(request: Request):
"""Handles GET requests to the root path"""
return {"message": "Hello World!"}
def POST(request: Request):
"""Handles POST requests to the root path"""
data = await request.json()
return {"received": data}The request object gives you access to headers, query parameters, and the request body.
Step 3: Add a dynamic route
Create a new folder structure for a dynamic user endpoint. The [user_id] folder tells FastAPI Route to capture that URL segment as a parameter:
mkdir -p routes/users/[user_id]Then create routes/users/[user_id]/route.py:
from fastapi_route import Request
def GET(request: Request, user_id: int):
"""GET /users/123 -> user_id = 123"""
return {"user_id": user_id, "name": f"User {user_id}"}
def DELETE(request: Request, user_id: int):
"""DELETE /users/123"""
return {"deleted": user_id}The parameter name from the folder (user_id) becomes a function parameter automatically. You can also specify the type hint (int) for automatic conversion.
Step 4: Run the development server
Start the development server with hot reload enabled:
fastapi-route devYou'll see output like:
============================================================
FASTAPI ROUTE DEVELOPMENT SERVER
============================================================
Server: http://127.0.0.1:8000
Mode: development
Hot reload: enabled
============================================================Now you can test your API:
# Test the root endpoint
curl http://localhost:8000/
# Test POST request
curl -X POST http://localhost:8000/ -H "Content-Type: application/json" -d '{"name":"Alice"}'
# Test dynamic route
curl http://localhost:8000/users/42
# Test DELETE
curl -X DELETE http://localhost:8000/users/42Visit http://localhost:8000/docs to see auto-generated API documentation.
What just happened?
You created a complete REST API without writing a single decorator. FastAPI Route automatically:
- Scanned your
routes/folder structure - Mapped folders to URL paths
- Converted
[user_id]folders to dynamic parameters - Registered each HTTP method function as a route
- Started a development server with hot reload
Any changes you make to your route files will automatically reload the server.
Next Steps
- File-based Routing - Learn how routes map to URLs in detail
- Dynamic Routes - Master path parameters and validation
- Route Groups - Organize routes without affecting URLs
- Middleware - Add authentication, logging, and rate limiting