Skip to main content

API Reference

Baby Basics provides a RESTful API for all tracking operations. All endpoints are under /api/v1/.

Authentication

All authenticated endpoints require a session token in the Authorization header:

Authorization: Bearer <your-token>

See the Authentication page for details on registration, login, logout, and session management.

Base URL

The base URL depends on your deployment:

  • Production: https://baby.bretzfam.com/api/v1
  • Development: https://dev.baby.bretzfam.com/api/v1
  • Local: http://localhost:3000/api/v1

Response Format

Single entity:

{
"feeding": { "id": "...", "timestamp": "...", ... }
}

List:

{
"feedings": [{ ... }, { ... }],
"count": 2
}

Error:

{
"error": {
"code": "VALIDATION_ERROR",
"message": "Human readable description",
"details": [{ "field": "email", "message": "Invalid email", "code": "invalid_string" }]
}
}

The details array is always present — empty [] for non-validation errors.

Error Handler

The central error handler at src/middleware/error-handler.ts automatically maps errors to the standard format:

  • Zod validation errors → 400 with field-level details
  • Prisma errors → P2002 (unique violation) = 409, P2025 (not found) = 404, P2003 (foreign key) = 400
  • AppError instances → custom status codes with structured details
  • Unknown errors → 500 with sanitized message

Interactive API Docs

When the server is running, interactive API documentation is available at /docs. The docs are auto-generated from Zod schemas via fastify-type-provider-zod and served with Swagger UI.

Endpoints

See the sidebar for individual endpoint documentation.