API Services
The frontend reaches data through a set of service classes under src/services/API/,
each extending a shared APIBase. They call a proxy backend at NEXT_PUBLIC_API_URL
(apiUrl = NEXT_PUBLIC_API_URL + /api), which forwards to the Repliers API.
The frontend never calls the Repliers API directly — always the proxy
(@configs/api apiUrl). Don’t hard-code Repliers hosts.
Request flow (search)
User filters (Filters) services/Search/types.ts
│ adapter / processParams (services/Search)
▼
Raw query params (ApiQueryParams) services/API/types/search.ts
│ APISearch.fetch({ get, post })
▼
Proxy backend → Repliers API → MLS
▼
ApiQueryResponse { listings: ApiListing[], count, statistics, aggregates }
│ transformers (services/Search) + utils/dataMapper resolvers
▼
UI-ready listingsAPIBase
src/services/API/APIBase.ts — the shared fetch layer every service extends:
| Member | Purpose |
|---|---|
getAbsoluteUrl(url) | Prefixes a relative path with apiUrl (absolute URLs pass through). |
getHeaders() | Async — sets Content-Type, X-Forwarded-* (via getForwardedFrom), and Authorization: Bearer <token> when a non-expired token exists. |
fetchRaw(request, options) | fetch wrapper; on 401 clears the token, on a network failure returns a synthetic 503. |
fetchJSON<T>(request, options) | Adds an AbortController timeout (apiRequestTimeout), parses JSON, resolves T on ok, else rejects ApiError. Server-side calls retry transient failures first — see below. |
ApiError(status, data) | Thrown on non-OK responses; carries the HTTP status and parsed data. |
Retries on transient failures
Server-side calls (build prerender, SSR, ISR regeneration) retry before surfacing an
error: 408, 425, 429, 500, 502, 503, 504, 522, 524 — plus the synthetic 503
fetchRaw returns for aborts and network errors. Attempts are capped by
apiRequestRetries (3) with a linear apiRetryBackoff (1s × attempt) between them,
both from @configs/api. Browser calls never retry, so user-facing failures stay
immediate.
After retries, the caller decides how to handle failure. Some page paths throw; others render a fallback or keep prior state. See the actual failure register. A caller-supplied AbortSignal also bypasses APIBase’s own timeout controller.
import { APISearch } from 'services/API'
const response = await APISearch.fetch({ get: params }) // → ApiQueryResponseService classes
All are exported from services/API (src/services/API/index.ts) as singletons and use
fetch*-style methods (not getX/postX):
| Class | Responsibility |
|---|---|
APISearch | Listing search — fetch() → /listings/search (GET or POST) → ApiQueryResponse. |
APIListingDetails | A single listing’s details + similar listings. |
APILocations | Locations / geography (/locations). |
APIEstimate | AVM estimate create / fetch. |
APIFavorites / APIImageFavorites | Saved listings / saved photos. |
APISavedSearch | Saved searches (CRUD + alerts). |
APIUser / APIAuth | User profile / authentication (redirect flow, OTP). |
APIAgent / APIFubUser | Agent portal / Follow Up Boss user. |
APIBuildings | Buildings / condos data. |
APIChat | AI NLP — fetchReply() turns a query into filters. |
APIContact | Contact-form submissions. |
APIWidgets | Embeddable widget content. |
APIPropertyGeometry | Property geometry / boundaries. |
APIBase / ApiError | Base fetch layer + typed error. |
locationsToGeoJson (same folder) converts location records to GeoJSON for the map.
Caller and contract register
Source review: e30dd9b47, 2026-11-02. This table identifies entry owners;
it is not a promise that every exported service has a live caller.
| Service | Principal caller / boundary | Contract details |
|---|---|---|
| APISearch | SearchService and filter/statistics consumers | /listings/search; nonempty body selects POST; fetchGraph uses /stats/graph; featured collections accept only sort/pagination |
| APIListingDetails | Listing route and detail UI | Board-aware detail; optional property history fallback; similar listings and last-update metadata |
| APILocations | Map, resolver, generated tree | Location lookup/boundaries, autosuggest, demographics; source/ID handling is operation-specific |
| APIAuth / APIUser | UserProvider and auth UI | OAuth/OTP/token exchange and profile fetch/update; update uses PATCH /user |
| APIFavorites | FavoritesProvider | Collection GET, POST MLS+board, raw DELETE by favorite id |
| APIImageFavorites | ImageFavoritesProvider | /user/assets/image-favorites; JSON add/remove responses and image id |
| APISavedSearch | SaveSearchProvider and search route | /searches/ CRUD, decoded names; raw DELETE differs from JSON create/update |
| APIEstimate | Estimate data/provider hooks | Suggestions, property details, create/update/fetch, comparables, agent branch |
| APIAgent | AgentClients/AgentEstimates/Agents providers | Agent/client/estimate management and send-estimate action |
| APIFubUser | Estimate SpecialOfferBanner | addTags posts to /user/boss/tag |
| APIBuildings | Building/catalog consumers | Building retrieval/search; CMS editorial assembly is a separate boundary |
| APIChat | Built-in chat and SupportAgent | POST /listings/nlp; prompt and NLP token |
| APIContact | Contact/scheduling/subscription forms | Mixed raw/JSON methods; see Forms |
| APIWidgets | Stats, dashboard, estimate statistics | /stats/widgets; propertyClass becomes query class |
| APIPropertyGeometry | Exported, no runtime caller found in the scan | Builds same-origin /api/geometry; no matching handler exists in the current inventory. An export does not establish endpoint availability |
CMS and integration services also call local Frontend Route Handlers. These frontend inventories do not replace the backend’s complete API reference.
Transformers (where they really live)
There is no services/API/transformers/ directory. Filter/response transformation lives
in:
services/Search/—adapter.ts/transformers.tsmapFilters↔ApiQueryParams(theprocessParamspipeline).src/utils/dataMapper/— resolvers (condo / residential) normalize a rawApiListinginto the detail sections the PDP renders.
Caching
Data fetching is native fetch + Next.js caching, with a custom production cache handler
(cache-handler.js, wired in production outside Vercel) backed by Redis
(redis) with ISR (revalidate) on server routes — not React Query or SWR (neither is a
dependency).
Related
- Data Models —
Filters,ApiListing, and the status model. - State Management — the providers that consume these services.