v0.2.0
ngx-api-client v0.2.0
Features
- make api versioning strategy and path prefix configurable (cd3aa42)
Version placement is now a strategy rather than a hardcoded /api/v{n} URL segment, and the static path prefix is configurable too.
provideApi({
baseUrl: 'https://api.example.com',
prefix: 'api', // '' or false to serve from the root
version: 1, // number | string ('2024-01-01', 'beta')
versioning: 'url', // 'query-param' | 'header' | 'media-type' | false
});versioning |
GET /orders |
|---|---|
'url' (default) |
/api/v1/orders |
'query-param' |
/api/orders?v=1 |
'header' |
/api/orders + X-API-Version: 1 |
'media-type' |
Accept: application/vnd.api.v1+json |
false |
/api/orders, no version sent |
- each strategy's naming is overridable —
parameterName,headerName,mediaType, and the URL versionprefix versionaccepts astringfor date- or label-based schemes; per-requestversion: falseandprefix: falseopt a single call out- new
API_PREFIXandAPI_VERSIONINGtokens, plus theApiVersioningStrategy,ApiVersioningConfigandAPI_VERSIONING_DEFAULTSexports
Notes
- No migration needed. Defaults are unchanged — requests still resolve to
{baseUrl}/api/v1{endpoint}— andAPI_VERSIONis still provided, now typednumber | string. - A header or query parameter set explicitly on a request is never overwritten by the versioning strategy, and a version placed in the URL is percent-encoded.
- With
versioning: falsethere is no strategy to carry a version, so a per-requestversionis ignored. - A trailing slash on
baseUrlis trimmed rather than producing a double slash. - Config options fall back to their defaults when passed explicitly as
undefined, so assembling config from optional sources (prefix: environment.apiPrefix) is safe.
Full Changelog: v0.1.0...v0.2.0