Documentation Index
Fetch the complete documentation index at: https://mintlify.com/AndrewwCO/Panahashi/llms.txt
Use this file to discover all available pages before exploring further.
services/api.js is the single source of truth for all backend communication in Panahashi. Every screen and context that needs data goes through this file — there are no inline fetch calls elsewhere in the app. This centralizes base URL configuration, authentication headers, and error handling in one place, keeping screen code clean and consistent.
Base URL
The backend base URL is exported asBASE_URL and must be updated when switching environments:
BASE_URL to point at the correct host before building for a new environment. Android emulators route 10.0.2.2 to the host machine’s localhost; iOS simulators and the web use 127.0.0.1 directly.
There is no runtime environment switching —
BASE_URL is a module-level constant. For multi-environment builds, consider using Expo’s app.config.js extra fields or a .env approach to inject the correct URL at build time.The request() function
All API calls go through a singlerequest() wrapper that handles URL construction, response parsing, and error throwing:
request() extracts json.data on success. On failure — either a non-2xx HTTP status or success: false in the body — it throws an Error using the backend’s message string. If the response body cannot be parsed as JSON at all, it throws with the HTTP status code.
Auth headers
authHeaders() fetches a fresh Firebase ID token on every call and returns a headers object ready to pass to fetch:
getIdToken() handles refresh internally when the token is near expiry. The extra parameter lets callers merge in additional headers if needed.
Public vs authenticated endpoints
Some endpoints are publicly accessible and do not require a Firebase token. Others requireauthHeaders(). The pattern is consistent throughout the file:
fetchBakeries()— list all active bakeriesfetchNearbyBakeries(lat, lng, radius)— location-based bakery searchfetchProductsByBakery(bakeryId)— products for a bakeryfetchReviewsByBakery(bakeryId)— reviews for a bakeryfetchPromotions(bakeryId)— active promotions
authHeaders()):
fetchCart(),addToCartApi(),updateCartItemApi(),clearCartApi()createOrder(),fetchMyOrders(),fetchOrderById()createPayment(),fetchPaymentByOrder()fetchMyProfile(),updateMyProfile()fetchFavorites(),toggleFavorite(),fetchFavoriteStatus(),removeFavorite()fetchMyLoyaltyCards(),fetchLoyaltyCard()fetchMyReviews(),canReviewOrder(),createReview()
Error handling
Errors fromrequest() surface as standard JavaScript Error objects. The error message is the backend’s own message string when available, or a fallback with the HTTP status code. Screens and contexts should wrap API calls in try/catch and set appropriate error state: