Logo
  1. Docs
  2. API References

WeaverseClient

Published on Oct 10, 2023, updated 11 months ago

The WeaverseClient class provides developers with a suite of methods to interact with Weaverse, manage caching strategies, and load theme-specific settings and pages.

Initialization

Developers construct an instance with appropriate configurations, including environmental variables, storefront information, and more, and then inject the instance into the app's load context for global accessibility.

Refer to the Project Structure article for a detailed walkthrough on setting up.

Methods

fetchWithCache

  • Arguments:

  • url: string - The endpoint to which the fetch request is made.

  • options: FetchWithCacheOptions - Optional. Configurations for the fetch request, including caching strategies and additional request initializations.

  • Returns: Promise<T> - A promise that resolves with the fetched data of the generic type T.

  • Description: Fetches data from an external API, applying the specified caching strategy.

    Refer to the Data Fetching and Caching to learn more.

loadThemeSettings

  • Arguments:

  • strategy: AllCacheOptions - Optional. The caching strategy to use when fetching theme settings.

  • Returns: Promise<any> - A promise that resolves with the theme settings data.

  • Description: Loads the theme settings, applying caching if not in design mode.

    Refer to the Global Theme Settings to learn more.

loadPage

  • Arguments:

  • params: LoadPageParams - Optional. Parameters for loading the page, including caching strategy and other request-specific data.

  • Returns: Promise<WeaverseLoaderData | null> - A promise that resolves with the data necessary for rendering a page or null in case of an error.

  • Description: Loads the data for a specific page, including configurations and content.

    Refer to the Rendering a Weaverse Page to learn more.

Was this article helpful?