Skip to content

v0.2.0

Choose a tag to compare

@github-actions github-actions released this 25 Jul 22:58
4fc2357

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 version prefix
  • version accepts a string for date- or label-based schemes; per-request version: false and prefix: false opt a single call out
  • new API_PREFIX and API_VERSIONING tokens, plus the ApiVersioningStrategy, ApiVersioningConfig and API_VERSIONING_DEFAULTS exports

Notes

  • No migration needed. Defaults are unchanged — requests still resolve to {baseUrl}/api/v1{endpoint} — and API_VERSION is still provided, now typed number | 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: false there is no strategy to carry a version, so a per-request version is ignored.
  • A trailing slash on baseUrl is 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