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
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:208
apiPrefix
apiPrefix: undefined | string;
Inherited from
ApiClient.apiPrefix
Source
api-client/dist/index.d.mts:216
authentication
authentication: undefined | Authentication;
ApiClientOptions.authentication
Inherited from
ApiClient.authentication
Source
api-client/dist/index.d.mts:224
baseUrl
baseUrl: string;
BaseUrl
Inherited from
ApiClient.baseUrl
Source
api-client/dist/index.d.mts:212
cache
cache: undefined | Cache;
Inherited from
ApiClient.cache
Source
api-client/dist/index.d.mts:232
customFetch
customFetch: undefined | (input, init?) => Promise<Response>;
Inherited from
ApiClient.customFetch
Source
api-client/dist/index.d.mts:220
debug
debug: undefined | boolean;
Inherited from
ApiClient.debug
Source
api-client/dist/index.d.mts:244
defaultLocale
defaultLocale: undefined | string;
ApiClientOptions.defaultLocale
Inherited from
ApiClient.defaultLocale
Source
api-client/dist/index.d.mts:228
logger
logger: undefined | object;
Inherited from
ApiClient.logger
Source
api-client/dist/index.d.mts:240
serializer
serializer: undefined | Serializer;
Inherited from
ApiClient.serializer
Source
api-client/dist/index.d.mts:236
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:274
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:257
getAccessToken()
protected getAccessToken(__namedParameters): Promise<OAuthTokenResponse>
Fetch the OAuth token from the BaseUrl
Parameters
• __namedParameters: OAuthCredentials
Returns
Promise
<OAuthTokenResponse
>
Inherited from
ApiClient.getAccessToken
Params
params - The credentials for getting an OAuth token. OAuthCredentials
Source
api-client/dist/index.d.mts:262
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:286
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:280
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