Pular para o conteúdo

API Reference

RedeCasas runs on 5 Cloudflare Workers that share a single D1 database (redecasas-chat), a shared KV namespace, and a shared R2 bucket. All public-facing APIs are REST/JSON over HTTPS.

Workers

WorkerSubdomain (prod)Route Prefix
Authauth.redecasas.com.br/api/auth/*, /api/users/*
Listingslisting.redecasas.com.br/api/listings*
Corretorescorretores.redecasas.com.br/api/corretores*
Billingbilling.redecasas.com.br/api/billing/*
Chatchat.redecasas.com.br/api/chat/*, /api/ws, /api/search*, /api/admin/*

Dev proxy (localhost): All routes are available via http://localhost:3000/api/*.

Authentication

All workers use the same session-cookie mechanism.

Set-Cookie: session={token}; HttpOnly; Secure; SameSite=Lax; Path=/; Max-Age=604800; Domain=redecasas.com.br
  • Token: Random UUID stored in KV as session:{token}
  • TTL: 7 days
  • Storage: KV namespace shared across all workers
  • Logout: Cookie cleared with Max-Age=0; KV key deleted

Making Authenticated Requests

Terminal window
curl -H "Cookie: session=<token>" https://auth.redecasas.com.br/api/auth/me

Common Patterns

Error Response Format

{
"error": {
"code": "VALIDATION_ERROR",
"message": "Human-readable description"
}
}

HTTP Status Codes

CodeMeaning
400Bad request
401Not authenticated
402Payment required (SUBSCRIPTION_REQUIRED)
403Not authorized
404Resource not found
409Conflict (duplicate)
422Validation failed
429Rate limited
500Server error

Pagination

List endpoints use ?page=1&limit=20 (max limit 50–100 depending on endpoint).

Response includes:

{
"listings": [...],
"total": 100,
"page": 1,
"limit": 20,
"totalPages": 5
}

Next Steps