@traveloka/core/api
This module handles how our page calls backend API.
Note that:
-
Server-side API calls are made directly to the backend internal endpoint (
*.tvlk.cloudis only recognized internally in our AWS network; you cannot hit this endpoint from outside AWS.) -
Client-side API calls are made to hit api-proxy first via the
/api/*route (you can verify that this route is handled by api-proxy). We needed API proxy to make it easier to comply with PCI-DSS security requirements (while it could otherwise take joint effort with all the backend teams to make adjustments). Note that sometimes we also put bot-control traps in the/api/*route (via AWS WAF dashboard).
Important files
-
Traveloka server-side API call helpers
packages/core/api/callAPI.tspackages/core/api/callAPIServerSide.ts
-
Traveloka client-side API call helpers
packages/core/api/callAPI.client.tspackages/core/api/callAPIClientSide.ts
-
Client-side API call hooks (automatically handles authentication errors; provides retry after the user has provided their OTP, etc.)
packages/core/api/useAPI.client.ts— Returns a fetcher function to call APIpackages/core/api/useSendBeacon.client.ts— Sends API usingnavigator.sendBeacon
-
Partner API call helpers (partner APIs use JWT authentication and doesn't use api-proxy)
packages/core/api/PartnerAPI.ts
How this module works
API-call lifecycle
TODO: Can copy from existing https://5.tvlk.dev/docs/guides/api-call#api-call-lifecycle. Important section: SSG preflight and cache
TODO: Can probably deprecate the use of
import { callAPI } from '@traveloka/core/api'in favor toimport { callAPI } from '@traveloka/core'. Originally seen here: https://5.tvlk.dev/docs/guides/api-routes#server-side-helpers