Use @boilerplate/helpers-requests and the "req..." function pattern for all API calls from apps. Use when adding or changing HTTP requests to the API, or when you see raw fetch() or axios in app code.
All outbound API requests from apps (web, management-web) must go through @boilerplate/helpers-requests, using the req... function pattern. Do not use raw fetch() or direct HTTP clients in app code for API calls.
No raw fetch for API calls
App code must not call fetch(url, ...) for app/management API endpoints. Use a req... helper from @boilerplate/helpers-requests instead.
Req... naming
reqFetch... (e.g. reqFetchBucket, reqFetchPublicBucket, reqFetchPublicBucketMessages).reqPost... (e.g. reqPostPublicBucketMessage).reqPatch..., reqPut..., reqDelete... as needed.Where helpers live
packages/helpers-requests/src/web/ (e.g. web/buckets.ts, web/auth.ts). Exported as webBuckets, webAuth, etc.packages/helpers-requests/src/management-web/. Exported as managementWebAuth, managementWebAdmins, etc.request() from packages/helpers-requests/src/request.js (consistent URL building, JSON, error shape, optional auth/locale).Adding a new endpoint
req... function in the appropriate module under web/ or management-web/.request<T>(baseUrl, path, options) with method, body, headers, credentials as needed.webBuckets) in packages/helpers-requests/src/index.ts.webBuckets.reqPostPublicBucketMessage(baseUrl, bucketId, body) and handle res.ok / res.error.message.Base URL
getServerApiBaseUrl() (from app lib); base URL already includes API version path.getApiBaseUrl() from app’s api-client (or equivalent); it includes version path.import { webBuckets } from '@boilerplate/helpers-requests';
import { getApiBaseUrl } from '../../../../../lib/api-client';
const baseUrl = getApiBaseUrl();
const res = await webBuckets.reqPostPublicBucketMessage(baseUrl, bucketId, {
senderName,
body,
isPublic,
});
if (!res.ok) {
setSubmitError(res.error.message ?? 'Failed to submit');
return;
}
// res.data available when res.ok
import { webBuckets } from '@boilerplate/helpers-requests';
import { getServerApiBaseUrl } from '../../../../../lib/server-request';
const baseUrl = getServerApiBaseUrl();
const res = await webBuckets.reqFetchPublicBucket(baseUrl, id);
if (!res.ok || res.data?.bucket === undefined) return null;
return res.data.bucket;
fetch(...) or direct HTTP calls to app backends.req... helper first, then use it in the app.