🚀 FastAPI & n8n Desde Cero

Aprende FastAPI, n8n, Nginx y Gunicorn

"FastAPI is a modern, fast, web framework for building APIs with Python."
Explorar Temas

📖 Temas del Curso

Haz clic en cualquier tema para ver el contenido detallado

📌 Introducción a FastAPI

FastAPI es un framework web moderno para construir APIs con Python 3.7+.

Ventajas:

  • Alto rendimiento (al nivel de NodeJS y Go)
  • Documentación automática (Swagger UI)
  • Validación de datos con Pydantic
  • Soporte para async/await
💡 Dato curioso: FastAPI es uno de los frameworks más rápidos para Python.
← Volver a temas

🔧 Instalación

# Instalar FastAPI y Uvicorn
pip install fastapi uvicorn[standard]

# Crear archivo main.py
# Ejecutar servidor
uvicorn main:app --reload

# En producción
uvicorn main:app --host 0.0.0.0 --port 8000
← Volver a temas

🌐 Primer Endpoint

from fastapi import FastAPI

app = FastAPI()

@app.get("/")
async def root():
    return {"message": "Hola Mundo"}

@app.get("/items/{item_id}")
async def read_item(item_id: int):
    return {"item_id": item_id}

Probar:

# Abrir navegador
http://localhost:8000/docs

# Swagger UI automático
← Volver a temas

📍 Path Parameters

@app.get("/users/{user_id}")
async def get_user(user_id: int):
    return {"user_id": user_id}

@app.get("/files/{file_path:path}")
async def read_file(file_path: str):
    return {"file": file_path}
← Volver a temas

🤖 ¿Qué es n8n?

n8n es una herramienta de automatización de workflows.

Características:

  • Node-based workflow automation
  • 200+ integraciones
  • Self-hostable
  • Gratuito para uso personal
← Volver a temas

🔧 Instalación n8n

# Con npm
npm install n8n -g
n8n start

# Con Docker
docker run -it --rm \
  --name n8n \
  -p 5678:5678 \
  n8nio/n8n

Acceder:

http://localhost:5678
← Volver a temas

📋 Workflows Básicos

Ejemplo: Webhook a Email

  1. Agregar nodo Webhook
  2. Configurar método HTTP
  3. Agregar nodo Email
  4. Conectar nodos
  5. Activar workflow
← Volver a temas

🔌 Integraciones

Integraciones populares:

  • Slack, Discord
  • Google Sheets, Airtable
  • GitHub, GitLab
  • Twilio, SendGrid
← Volver a temas

🌐 Introducción a Nginx

Nginx es un servidor web y proxy reverso.

Usos comunes:

  • Load balancing
  • Proxy reverso
  • Caché HTTP
  • SSL/TLS termination
← Volver a temas

⚙️ Configurar Nginx

# /etc/nginx/sites-available/miapp
server {
    listen 80;
    server_name midominio.com;

    location / {
        proxy_pass http://127.0.0.1:8000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }

    location /static/ {
        alias /var/www/static/;
    }
}
← Volver a temas

🦄 Gunicorn WSGI

# Instalar
pip install gunicorn

# Ejecutar FastAPI con Uvicorn workers
gunicorn main:app -w 4 -k uvicorn.workers.UvicornWorker

# Con bind específico
gunicorn main:app -w 4 -k uvicorn.workers.UvicornWorker --bind 0.0.0.0:8000
← Volver a temas

🚀 Deploy Producción

Arquitectura completa:

Internet → Nginx (puerto 80/443)
              ↓
         Gunicorn (workers)
              ↓
        FastAPI app

Systemd service:

[Unit]
Description=FastAPI App

[Service]
User=www-data
WorkingDirectory=/var/www/miapp
ExecStart=/usr/bin/gunicorn main:app -w 4 -k uvicorn.workers.UvicornWorker

[Install]
WantedBy=multi-user.target
← Volver a temas

📚 Contenido del Curso

Módulo 1: FastAPI

  • Introducción a FastAPI
  • Instalación
  • Primer endpoint
  • Path parameters
Ir a temas →

Módulo 2: n8n

  • ¿Qué es n8n?
  • Instalación n8n
  • Workflows básicos
  • Integraciones
Ir a temas →

Módulo 3: Nginx & Gunicorn

  • Introducción a Nginx
  • Configurar Nginx
  • Gunicorn WSGI
  • Deploy producción
Ir a temas →

📝 Ejemplos Rápidos

FastAPI App

from fastapi import FastAPI

app = FastAPI()

@app.get("/")
async def root():
    return {"message": "Hola Mundo"}

Nginx Config

server {
    listen 80;
    location / {
        proxy_pass http://127.0.0.1:8000;
    }
}

📖 Recursos Adicionales

Herramientas

  • Uvicorn
  • Gunicorn
  • Docker

Comunidades

  • FastAPI GitHub
  • n8n Forum
  • Stack Overflow

👨‍💻 Desarrollado por Isaac Esteban Haro Torres

Ingeniero en Sistemas · Full Stack · Automatización · Data

📧 Email: zackharo1@gmail.com

📱 WhatsApp: 098805517

💻 GitHub: github.com/ieharo1

🌐 Portafolio: ieharo1.github.io/portafolio-isaac.haro/