Skip to content

Parte 1: Setup y Primera Ruta

Estado verificado al 28 de marzo de 2026. Nota de runtime: FastFN auto-instala dependencias locales por función desde requirements.txt / package.json; en fastfn dev --native necesitas runtimes instalados en host, mientras que fastfn dev depende de Docker daemon activo.

Vista rápida

  • Complejidad: Principiante
  • Tiempo típico: 15-20 minutos
  • Resultado: proyecto limpio con endpoint GET /tasks y entrada en OpenAPI

1. Setup limpio

mkdir -p task-manager-api/functions/tasks
cd task-manager-api

2. Implementa la primera ruta (elige runtime)

Archivo: functions/tasks/handler.js

exports.handler = async () => ({
  status: 200,
  body: [
    { id: 1, title: "Aprender FastFN", completed: false },
    { id: 2, title: "Publicar primer endpoint", completed: false }
  ]
});

Archivo: functions/tasks/handler.py

def handler(_event):
    return {
        "status": 200,
        "body": [
            {"id": 1, "title": "Aprender FastFN", "completed": False},
            {"id": 2, "title": "Publicar primer endpoint", "completed": False},
        ],
    }

Archivo: functions/tasks/handler.rs

use serde_json::json;

pub fn handler(_event: serde_json::Value) -> serde_json::Value {
    json!({
        "status": 200,
        "body": [
            { "id": 1, "title": "Aprender FastFN", "completed": false },
            { "id": 2, "title": "Publicar primer endpoint", "completed": false }
        ]
    })
}

Archivo: functions/tasks/handler.php

<?php

function handler(array $event): array {
    return [
        'status' => 200,
        'body' => [
            ['id' => 1, 'title' => 'Aprender FastFN', 'completed' => false],
            ['id' => 2, 'title' => 'Publicar primer endpoint', 'completed' => false],
        ],
    ];
}

3. Ejecuta local

fastfn dev functions

4. Valida primera request (por runtime)

curl -sS 'http://127.0.0.1:8080/tasks'
curl -sS 'http://127.0.0.1:8080/tasks'
curl -sS 'http://127.0.0.1:8080/tasks'
curl -sS 'http://127.0.0.1:8080/tasks'

Forma esperada:

[
  { "id": 1, "title": "...", "completed": false },
  { "id": 2, "title": "...", "completed": false }
]

5. Valida visibilidad OpenAPI

curl -sS 'http://127.0.0.1:8080/openapi.json' | jq '.paths | has("/tasks")'

Salida esperada:

true

Navegador mostrando la respuesta JSON en /tasks

Solución de problemas

  • 503: revisa /_fn/health y dependencias runtime
  • ruta no encontrada: confirma handler en functions/tasks/
  • OpenAPI sin path: ejecuta curl -X POST http://127.0.0.1:8080/_fn/reload

Próximo paso

Ir a la Parte 2: Enrutamiento y Datos

Enlaces relacionados

Última revisión: 28 de marzo de 2026 · Docs en fastfn.dev