How to Build an API in 10 Minutes
Published May 2026APIs are the backbone of modern apps. In this tutorial, you will build a fully functional REST API with Python FastAPI and deploy it for free on Railway — all in under 10 minutes.
What You Will Build
A simple Task API with CRUD operations: create, read, update, delete tasks. This is the foundation of 90% of backend applications.
Prerequisites
- Python 3.10+ installed
- A Railway account (free tier available)
- Basic Python knowledge
Step 1: Set Up Your Project
mkdir fastapi-task-api
cd fastapi-task-api
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install fastapi uvicorn
Step 2: Write the API Code
Create main.py:
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from typing import List, Optional
app = FastAPI()
class Task(BaseModel):
id: int
title: str
completed: bool = False
tasks = []
@app.get("/tasks", response_model=List[Task])
def get_tasks():
return tasks
@app.post("/tasks", response_model=Task)
def create_task(task: Task):
tasks.append(task)
return task
@app.get("/tasks/{task_id}")
def get_task(task_id: int):
for task in tasks:
if task.id == task_id:
return task
raise HTTPException(status_code=404, detail="Task not found")
@app.delete("/tasks/{task_id}")
def delete_task(task_id: int):
for i, task in enumerate(tasks):
if task.id == task_id:
tasks.pop(i)
return {"message": "Task deleted"}
raise HTTPException(status_code=404, detail="Task not found")
Step 3: Test Locally
uvicorn main:app --reload
Visit http://localhost:8000/docs for interactive API documentation.
Step 4: Deploy to Railway
- Install Railway CLI:
npm i -g @railway/cli - Login:
railway login - Init project:
railway init - Deploy:
railway up
Railway auto-detects FastAPI. Your API is now live with a public URL.
Step 5: Add a Database (Optional)
Replace the in-memory list with SQLite or PostgreSQL via Railway. FastAPI works seamlessly with SQLAlchemy and async database drivers.
Next Steps
- Add authentication with OAuth2 and JWT
- Deploy with your own VPS for full control
- Add rate limiting and input validation
- Connect a frontend built with React or Vue
You now have a production API pattern you can reuse for any project. FastAPI plus Railway is the fastest backend stack in 2026.