WeaverseClient
TheWeaverseClient
class is a server-side utility that provides methods to interact with Weaverse services, fetch content, manage caching strategies, and load theme settings and page data for your Hydrogen storefront.
Initialization
TheWeaverseClient
is typically initialized in your server.ts
file and injected into your app’s load context:
Type Definition
Methods
fetchWithCache
Fetches data from an external API with configurable caching strategies.url: string
- The endpoint URLoptions?: RequestInit & { strategy?: AllCacheOptions }
- Cache and fetch configurationstrategy
- Caching strategy with options likemaxAge
,staleWhileRevalidate
, etc.- Other standard
fetch
options (headers
,method
, etc.)
Promise<T>
- A promise that resolves with the fetched data
loadThemeSettings
Loads the global theme settings for the current Weaverse project.strategy?: AllCacheOptions
- Optional caching strategy for the theme settings request
Promise<HydrogenThemeSettings>
- The theme settings object
loadPage
Loads a page’s data from Weaverse, including running component loaders.params
- Object containing:type?: PageType
- Type of page (‘INDEX’, ‘PRODUCT’, etc.)locale?: string
- Locale for the pagehandle?: string
- Handle/slug for the pagestrategy?: AllCacheOptions
- Caching strategy
Promise<WeaverseLoaderData | null>
- Page data object or null if not found
execComponentLoader
Executes a component’s loader function to fetch its data.item: HydrogenComponentData
- Component data object
Promise<HydrogenComponentData>
- Component data with loader data added
loadPage
to process component loaders.
generateFallbackPage
Generates a fallback page when the requested page data isn’t available.message: string
- Message to display on the fallback page
HydrogenPageData
- A basic page data object with the message
Related
- useWeaverse - Hook for accessing Weaverse instance client-side
- Data Fetching and Caching - Advanced guide on data fetching