Creates a new instance of the JsonApiClient.
The base URL of the API. BaseUrl
Optional
options: ApiClientOptions(Optional) Additional options for configuring the API client. JsonApiClientOptions
Private
#privateApiClientOptions.apiPrefix
ApiClientOptions.authentication
BaseUrl
ApiClientOptions.cache
ApiClientOptions.customFetch
ApiClientOptions.debug
ApiClientOptions.defaultLocale
ApiClientOptions.logger
link DecoupledRouterClient
ApiClientOptions.serializer
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.
The RequestInit options to which the authorization header should be added.
The updated RequestInit options with the authorization header, if applicable.
Create a resource of the specified type using the provided body.
The type of the entity with bundle information.
The body of the request.
Optional
options: CreateOptions(Optional) Additional options for customizing the request. CreateOptions
A Promise that resolves to a Response object or RawApiResponseWithData.
This method initiates the creation of a resource by sending a POST request to the API.
const responseBody = await createResource("node--page", `{
"data": {
"type": "node--page",
"attributes": {
"title": "My custom title",
"body": {
"value": "Custom value",
"format": "plain_text"
}
}
}
}, { rawResponse: false });
Generates an endpoint URL based on the provided parameters.
The endpoint URL as a string.
params - The parameters to use for creating the URL. EndpointUrlSegments
Deletes a resource of the specified type using the provided resource ID.
The type of the entity with bundle information.
The ID of the resource to be deleted.
Optional
options: DeleteOptions(Optional) Additional options for customizing the request. DeleteOptions
A Promise that resolves to a Response object or RawApiResponseWithData.
const responseBody = await deleteResource("node--page", "7cbb8b73-8bcb-4008-874e-2bd496bd419d", { rawResponse: false });
Protected
getRetrieves a cached response from the cache.
The cache key to use for retrieving the cached response.
A promise wrapping the cached response as a generic type.
Retrieves a collection of data of a specific entity type and bundle from the JSON:API.
The type of resource to retrieve, in the format "entityType--bundle". For example, "node--page". EntityTypeWithBundle
Optional
options: GetOptions(Optional) Additional options for customizing the request. GetOptions
A Promise that resolves to the JSON data of the requested resource.
Using JSONAPI.CollectionResourceDoc type from the jsonapi-typescript package
const collection = await jsonApiClient.get<JSONAPI.CollectionResourceDoc<string, Recipe>>("node--recipe");
Retrieves data for a resource by ID of a specific entity type and bundle from the JSON:API.
The type of resource to retrieve, in the format "entityType--bundle". For example, "node--page". EntityTypeWithBundle
The ID of the individual resource to retrieve.
Optional
options: GetOptions(Optional) Additional options for customizing the request. GetOptions
A Promise that resolves to the JSON data of the requested resource.
Using JSONAPI.CollectionResourceDoc type from the jsonapi-typescript package
const collection = await jsonApiClient.get<JSONAPI.CollectionResourceDoc<string, Recipe>>("node--recipe");
Attempts to resolve a path to a resource and then fetches the resolved resource.
The path to resolve and fetch.
Optional
options: GetOptions(Optional) Additional options for customizing the request. GetOptions
const article = await jsonApiClient.getResourceByPath("/articles/give-it-a-go-and-grow-your-own-herbs");
Processes the API response and returns the JSON data.
The response object from the API.
The cache key to use for caching the response.
Optional
options: GetOptions | UpdateOptions | CreateOptions(Optional) Additional options for customizing the request. CreateOptions
Updates a resource of the specified type using the provided resource ID.
The type of the entity with bundle information.
The ID of the resource to be updated.
The body of the request.
Optional
options: UpdateOptions(Optional) Additional options for customizing the request. UpdateOptions
A Promise that resolves to a Response object or RawApiResponseWithData.
This method initiates the update of a resource by sending a PATCH request to the API.
const responseBody = await updateResource("node--page", "7cbb8b73-8bcb-4008-874e-2bd496bd419d", `{
"data": {
"type": "node--page",
"id": "11fc449b-aca0-4b74-bc3b-677da021f1d7",
"attributes": {
"drupal_internal__nid": 2,
"drupal_internal__vid": 3,
"langcode": "en",
"revision_log": null,
"status": true,
"title": "test 2"
}
}
}`, { rawResponse: false });
Static
createGenerates a cache key based on the provided parameters.
A promise wrapping the generated cache key as a string.
params - The parameters to use for generating the cache key. EndpointUrlSegments
// Generate a cache key with entityTypeId and bundleId only
const key1 = await MyClass.createCacheKey('entity1', 'bundle1');
// key1: 'entity1--bundle1'
// Generate a cache key with entityTypeId, bundleId, localeSegment, and queryString
const key2 = await MyClass.createCacheKey('entity2', 'bundle2', 'en-US', 'param1=value1¶m2=value2');
// key2: 'en-US--entity2--bundle2--<sha256_hash_of_query_string>'
Static
getGenerated using TypeDoc
JSON:API Client class provides functionality specific to JSON:API server.
See