@drupal-js-sdk/xhr
Overview
HTTP client abstractions with a unified interface, supporting native fetch or Axios. Used by all SDK packages for requests.
Usage
JavaScript
import { FetchClient } from "@drupal-js-sdk/xhr";
const client = new FetchClient({ baseURL: "https://example.com" }).addDefaultHeaders({
"X-App": "docs",
});
const response = await client.call("GET", "/jsonapi/node/article");
Public API
class FetchClient
implements XhrInterface
Constructor
setClient
getClient
addDefaultHeaders
call
class AxiosClient
implements XhrInterface
Constructor
setClient
getClient
addDefaultHeaders
call
Notes
- Both clients adhere to
XhrInterface
from@drupal-js-sdk/interfaces
.