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
| Worker | Subdomain (prod) | Route Prefix |
|---|---|---|
| Auth | auth.redecasas.com.br | /api/auth/*, /api/users/* |
| Listings | listing.redecasas.com.br | /api/listings* |
| Corretores | corretores.redecasas.com.br | /api/corretores* |
| Billing | billing.redecasas.com.br | /api/billing/* |
| Chat | chat.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.
Session Cookie
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
curl -H "Cookie: session=<token>" https://auth.redecasas.com.br/api/auth/meCommon Patterns
Error Response Format
{ "error": { "code": "VALIDATION_ERROR", "message": "Human-readable description" }}HTTP Status Codes
| Code | Meaning |
|---|---|
400 | Bad request |
401 | Not authenticated |
402 | Payment required (SUBSCRIPTION_REQUIRED) |
403 | Not authorized |
404 | Resource not found |
409 | Conflict (duplicate) |
422 | Validation failed |
429 | Rate limited |
500 | Server 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
- See Endpoints for the complete endpoint reference
- See Quick Start for copy-paste curl examples