Skip to content

DecoupledRouterClient

Decoupled Router Client class provides functionality specific to the decoupled-router module.

See

  • ApiClientOptions
  • BaseUrl

Extends

  • ApiClient

Constructors

new DecoupledRouterClient()

new DecoupledRouterClient(baseUrl, options?): DecoupledRouterClient

Creates a new instance of the DecoupledRouterClient.

Parameters

baseUrl: string

The base URL of the API. BaseUrl

options?: ApiClientOptions

(Optional) Additional options for configuring the API client. ApiClientOptions

Returns

DecoupledRouterClient

Overrides

ApiClient.constructor

Source

decoupled-router-client/src/DecoupledRouterClient.ts:23

Properties

#private

private #private: any;

Inherited from

ApiClient.#private

Source

api-client/dist/index.d.mts:192


apiPrefix

apiPrefix: undefined | string;

ApiClientOptions.apiPrefix

Inherited from

ApiClient.apiPrefix

Source

api-client/dist/index.d.mts:200


authentication

authentication: undefined | Authentication;

ApiClientOptions.authentication

Inherited from

ApiClient.authentication

Source

api-client/dist/index.d.mts:208


baseUrl

baseUrl: string;

BaseUrl

Inherited from

ApiClient.baseUrl

Source

api-client/dist/index.d.mts:196


cache

cache: undefined | Cache;

ApiClientOptions.cache

Inherited from

ApiClient.cache

Source

api-client/dist/index.d.mts:216


customFetch

customFetch: undefined | (input, init?) => Promise<Response>;

ApiClientOptions.customFetch

Inherited from

ApiClient.customFetch

Source

api-client/dist/index.d.mts:204


debug

debug: undefined | boolean;

ApiClientOptions.debug

Inherited from

ApiClient.debug

Source

api-client/dist/index.d.mts:228


defaultLocale

defaultLocale: undefined | string;

ApiClientOptions.defaultLocale

Inherited from

ApiClient.defaultLocale

Source

api-client/dist/index.d.mts:212


logger

logger: undefined | object;

ApiClientOptions.logger

Inherited from

ApiClient.logger

Source

api-client/dist/index.d.mts:224


serializer

serializer: undefined | Serializer;

ApiClientOptions.serializer

Inherited from

ApiClient.serializer

Source

api-client/dist/index.d.mts:220

Methods

addAuthorizationHeader()

addAuthorizationHeader(options): Promise<RequestInit>

Adds an authorization header to the provided RequestInit options if authentication of type “Basic” is configured. If the authentication type is “OAuth”, it will fetch a new access token or use the stored access token if it exists and is still valid. if the authentication type is “Custom”, it will use the provided value.

Parameters

options: undefined | RequestInit

The RequestInit options to which the authorization header should be added.

Returns

Promise<RequestInit>

The updated RequestInit options with the authorization header, if applicable.

Inherited from

ApiClient.addAuthorizationHeader

Source

api-client/dist/index.d.mts:261


createURL()

createURL(__namedParameters): string

Generates an endpoint URL based on the provided parameters.

Parameters

__namedParameters

__namedParameters.localeSegment?: string

__namedParameters.path: string

Returns

string

The endpoint URL as a string.

Params

params - The parameters to use for creating the URL.

Source

decoupled-router-client/src/DecoupledRouterClient.ts:90


fetch()

fetch(input, init?): Promise<FetchReturn>

Uses customFetch if it is set, otherwise uses the default fetch

Parameters

input: RequestInfo | URL

RequestInfo

init?: RequestInit

RequestInit

Returns

Promise<FetchReturn>

a response wrapped in a promise

Inherited from

ApiClient.fetch

Source

api-client/dist/index.d.mts:241


getAccessToken()

protected getAccessToken(__namedParameters): Promise<OAuthTokenResponse>

Fetch the OAuth token from the BaseUrl

Parameters

__namedParameters

__namedParameters.clientId: string

__namedParameters.clientSecret: string

Returns

Promise<OAuthTokenResponse>

Inherited from

ApiClient.getAccessToken

Param0

the Client ID

Param1

the Client secret

Source

api-client/dist/index.d.mts:247


getCachedResponse()

getCachedResponse<T>(cacheKey): Promise<null | NonNullable<Awaited<T>>>

Retrieves a cached response from the cache.

Type parameters

T

Parameters

cacheKey: string

The cache key to use for retrieving the cached response.

Returns

Promise<null | NonNullable<Awaited<T>>>

A promise wrapping the cached response as a generic type.

Inherited from

ApiClient.getCachedResponse

Source

api-client/dist/index.d.mts:273


log()

log(level, message): void

Calls the appropriate logger method based on level

Parameters

level: LogLevels

level based on npm log levels

message: string

the message to log

Returns

void

Inherited from

ApiClient.log

Source

api-client/dist/index.d.mts:267


translatePath()

translatePath(path, options?): Promise<DecoupledRouterResponse | RawDecoupledRouterResponse>

Translates a path in the consuming application to a Drupal entity.

Parameters

path: string

the path to translate

options?: GetOptions

Returns

Promise<DecoupledRouterResponse | RawDecoupledRouterResponse>

A Promise that resolves to the JSON data provided by the router.

Source

decoupled-router-client/src/DecoupledRouterClient.ts:34


createCacheKey()

static createCacheKey(__namedParameters): string

Generates a cache key based on the provided parameters.

Parameters

__namedParameters

__namedParameters.cacheKey?: string

__namedParameters.localeSegment?: string

__namedParameters.path?: string

Returns

string

The generated cache key as a string.

Params

params - The parameters to use for generating the cache key.

Example

const key1 = await this.createCacheKey('en', '/articles/give-your-oatmeal-the-ultimate-makeover');
// key1: 'en--/articles/give-your-oatmeal-the-ultimate-makeover'

Source

decoupled-router-client/src/DecoupledRouterClient.ts:110