agentleFS
contactandrewchl-wqcontactandrewchl-wq/turtle-mcp/skills/backend-api-design/SKILL.md

backend-api-design

Skill2 starsChanged 5 months agoMITView on GitHub

Diseño de APIs HTTP/REST y JSON: recursos, verbos, códigos de estado, versionado, paginación, idempotencia, errores estructurados, contratos documentados. Cargá al diseñar un endpoint nuevo o cambiar un contrato.

3 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 2 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    204: No Content — éxito sin cuerpo (típico DELETE).

    line 44
  2. Distinctive:

    404: Not Found — el recurso no existe.

    line 48
  3. Distinctive:

    Documentá ejemplos en la spec, no solo tipos.

    line 111

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Backend API design

Cuándo usar

  • Crear un endpoint nuevo o cambiar uno existente.
  • Diseñar un contrato entre frontend y backend o entre servicios.
  • Revisar un PR que toca rutas, payloads o códigos de estado.

Recursos y verbos

Pensá en recursos (sustantivos), no en acciones:

AcciónVerboRuta
ListarGET/usuarios
ObtenerGET/usuarios/{id}
CrearPOST/usuarios
ReemplazarPUT/usuarios/{id}
Modificar parcialPATCH/usuarios/{id}
BorrarDELETE/usuarios/{id}
Sub-recursoGET/usuarios/{id}/sesiones

Acciones que no son CRUD: POST /usuarios/{id}/activar. No POST /activarUsuario.

Códigos de estado

Los más usados, sin inventar:

  • 200 OK — éxito con cuerpo.
  • 201 Created — creado, devolvé Location con la URL.
  • 204 No Content — éxito sin cuerpo (típico DELETE).
  • 400 Bad Request — payload o parámetro inválido.
  • 401 Unauthorized — falta credencial o es inválida.
  • 403 Forbidden — autenticado, pero no autorizado.
  • 404 Not Found — el recurso no existe.
  • 409 Conflict — conflicto de estado (duplicado, versión).
  • 422 Unprocessable — sintaxis ok, semántica no.
  • 429 Too Many Requests — rate limit.
  • 500 Internal Server Error — bug nuestro.
  • 503 Service Unavailable — caído / mantenimiento.

Nunca 200 con { "error": ... }. El estado va en el HTTP.

Errores estructurados

Adoptá un formato único en toda la API. Recomendado: RFC 9457 (Problem Details):

{
  "type": "https://api.tu-app.com/errors/usuario-no-encontrado",
  "title": "Usuario no encontrado",
  "status": 404,
  "detail": "No existe un usuario con id 'abc123'.",
  "instance": "/usuarios/abc123"
}

Incluí campos extras útiles: errors (lista de fallos por campo), traceId. Nunca devuelvas stack traces ni nombres de tablas a un cliente.

Versionado

  • En la URL (/v1/usuarios) — simple, cacheable, visible.
  • O en el header (Accept: application/vnd.tuapp.v1+json) — para puristas.
  • Subí versión solo en cambio incompatible. Agregar campo opcional no rompe.

Paginación

Siempre paginá listas con potencial de crecer:

GET /usuarios?cursor=eyJpZCI6MTAwfQ&limit=50

Respuesta:

{ "items": [...], "next_cursor": "eyJpZCI6MTUwfQ", "limit": 50 }

Cursor > offset: offset rompe si entran/salen filas. limit con tope server-side.

Idempotencia

  • GET, PUT, DELETE deben ser idempotentes por contrato HTTP.
  • POST que crea recurso: aceptá header Idempotency-Key y deduplicá por N horas. Pagos, mensajes, jobs siempre idempotentes.

Filtros, orden, búsqueda

  • Filtros: ?status=active&role=admin.
  • Orden: ?sort=-created_at (- = desc).
  • Búsqueda: ?q=.... Diferenciá de filtros exactos.

Validación y contrato

  • Defina el contrato en OpenAPI / JSON Schema y generá tipos para el cliente.
  • Validá entrada en el borde (DTO/schema), no dentro de la lógica.
  • Documentá ejemplos en la spec, no solo tipos.

Reglas duras

  • Sin secretos en URLs (van en headers o body).
  • Sin verbos en rutas (/getUser ❌ → GET /users/{id} ✅).
  • Sin breaking changes silenciosos. Deprecar primero (header Deprecation, Sunset), remover después.
  • Toda mutación loguea quién + qué + cuándo, sin PII completa.
  • Rate limit por defecto. 429 con header Retry-After.

Validación

  • Tests por endpoint: happy path + cada código de error.
  • Tests E2E del contrato (Pact, Dredd, schemathesis).
  • Docs actualizadas en el mismo PR que cambia el contrato.

Relacionadas

[[backend-data-modeling]] · [[backend-observability]] · [[security-authn-authz]] · [[security-owasp]]

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.