The SitecoreClient API
The SitecoreClient class is a generic, framework-agnostic client that you can use to interact with SitecoreAI's headless APIs and services. It provides a unified interface for retrieving and managing content, layout, dictionary data, error pages, preview data, sitemaps, robots.txt, and other site-related information from a SitecoreAI backend, typically via GraphQL endpoints.
It enables the following:
-
Content retrieval - fetch page layout data, preview data, and component data for rendering pages and components.
-
Localization - retrieve dictionary phrases for specific sites and locales.
-
Personalization - provide personalized content by handling variant IDs and rewriting layout data accordingly.
-
SEO support - fetch sitemap XML and
robots.txtcontent for SEO and crawler support. -
Static paths - generate static paths for all site pages, enabling workflows such as static site generation.
-
Extensibility - implement custom services using dependency injection in the constructor.
Configuration
To initialize the SitecoreClient, you need to provide a configuration object of type SitecoreClientInit.
The configuration object is derived from the SitecoreConfig type, which includes all settings necessary for connecting to SitecoreAI's headless services. It includes a custom property that allows you to inject custom implementations for the services used by SitecoreClient.
Key methods
Here is a list of the methods exposed by the SitecoreClient class, including their purpose, input parameters, and expected outputs. You can learn more about the related services by referring to the linked API documentation.
|
Method name |
Description |
Type signature |
|---|---|---|
|
|
(Next.js only) Uses |
|
|
|
Uses |
|
|
|
Uses |
|
|
|
Retrieves the head
|
Both |
|
|
Uses |
|
|
|
Uses |
|
|
|
Uses |
|
|
|
Uses |
|
|
|
Uses |
|
|
|
Uses |
|
|
|
Exposes a simple, typed way to run raw GraphQL requests directly from Examples: RequestResponse RequestResponse |
|