ApiCore class provides a robust HTTP client for communicating with the EGO Real Estate API. It includes automatic retry logic for rate limiting and network errors.
Class Definition
Configuration
Methods
request()
Makes an authenticated HTTP request to the EGO Real Estate API with automatic retry logic.
Parameters
API endpoint path (e.g.,
/properties, /property/123)Standard fetch API options object. The following headers are automatically added:
AuthorizationToken: API token from environmentContent-Type:application/jsonLanguage: Language code (es-ES or en-US)
Language code for the API request. Common values:
"es-ES"- Spanish (default)"en-US"- English
Returns
Returns a Promise that resolves to the typed response data. The type parameter
T defines the expected response shape.Retry Logic
Therequest() method implements intelligent retry logic:
- Rate Limiting (429): Automatically retries with exponential backoff delays (2s, 5s, 10s)
- Network Errors: Retries network failures with the same backoff strategy
- Maximum Attempts: Up to 3 retry attempts after the initial request
- Logging: Console logs all retry attempts with attempt numbers
Error Handling
The method throws errors in the following cases:- Non-429 HTTP errors (4xx, 5xx) after the first attempt
- After exhausting all retry attempts
- JSON parsing failures
Authentication
Authentication is handled automatically using thePUBLIC_EGO_API_TOKEN environment variable. The token is sent in two ways for maximum compatibility:
- HTTP Header:
AuthorizationToken: <token> - URL Query Parameter:
?AuthorizationToken=<token>
Usage Examples
Basic Request
Request with English Language
POST Request
Handling Errors
Console Logging
The ApiCore class provides detailed console logging:Technical Details
CORS Configuration
All requests are made withmode: "cors" to enable cross-origin requests.
Content Type Detection
The response handler checks theContent-Type header:
application/json: Parses and returns JSON- Other types: Returns
{ success: true }for successful requests
Sleep Function
Retry delays are implemented using an internal sleep utility:Source Location
src/services/api/api.ts:1-78