Typed client creation
View as MarkdownIdentity
Section titled “Identity”createApiClient and ApiError from @sapporta/shared/client; getApiBase
from @sapporta/frontend/platform.
Contract
Section titled “Contract”createApiClient(contract, options)returns a throwing client whose contract key becomes the method name.- Calls pass
params,query, andbodyaccording to the route contract. - A
QueryParamRecordvalue may contain a readonly string array. The client serializes that array as repeated URL keys in order, which preserves same-key table filters instead of collapsing them. Numeric table query inputs remain strings at this client boundary and are coerced by the shared contract on the server. - Use
{ baseUrl: getApiBase }, not{ baseUrl: getApiBase() }. The client calls the resolver immediately before every request and prepends the result to the contract path. validateResponsedefaults totrue. A response-schema mismatch rejects the call before response unwrapping.- A valid 2xx response returns its body. A non-2xx response that reaches
unwrapping throws
ApiErrorwith numericstatusand anunknownbody. - Transport and response-validation failures pass through without fabricated HTTP statuses.
baseHeadersdefaults to{ "Content-Type": "application/json" }.credentialsis passed tofetch; use the value required by the generated same-origin or split-origin authentication configuration.- Setting
validateResponse: falsedisables client response-schema proof and should be an explicit compatibility decision, not routine feature setup.