How to Build an API in 10 Minutes

Published May 2026

APIs 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

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

  1. Install Railway CLI: npm i -g @railway/cli
  2. Login: railway login
  3. Init project: railway init
  4. 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

You now have a production API pattern you can reuse for any project. FastAPI plus Railway is the fastest backend stack in 2026.