externalStarlightClient <D>
Index
Selector Accessors
Instance Methods
Other Methods
Selector Accessors
externalcollections
Returns a DynamicCollectionSelector, which is a CollectionSelector with support for creating CollectionInstances using the dynamic syntax.
This is an accessor, which means that it should be used just like a common object parameter. For instance:
import Starlight from '@starlightcms/js-sdk'
const response = await Starlight.collections.list()See DynamicCollectionSelector for more info.
Returns DynamicCollectionSelector
externalmedia
Returns a MediaSelector.
This is an accessor, which means that it should be used just like a common object parameter. For instance:
import Starlight from '@starlightcms/js-sdk'
const response = await Starlight.media.list()See MediaSelector for more info.
Returns MediaSelector
externalmodels
Returns a DynamicModelSelector, which is a ModelSelector with support for creating ModelInstances using the dynamic syntax.
This is an accessor, which means that it should be used just like a common object parameter. For instance:
import Starlight from '@starlightcms/js-sdk'
const response = await Starlight.models.list()See DynamicModelSelector for more info.
Returns DynamicModelSelector<D>
externalsearch
Returns a SearchSelector.
This is an accessor, which means that it should be used just like a common object parameter. For instance:
import Starlight from '@starlightcms/js-sdk'
const response = await Starlight.search.entries()See SearchSelector for more info.
Returns SearchSelector
externalsingletons
Returns a SingletonSelector.
This is an accessor, which means that it should be used just like a common object parameter. For instance:
import Starlight from '@starlightcms/js-sdk'
const response = await Starlight.singletons.list()See SingletonSelector for more info.
Returns SingletonSelector
Instance Methods
externalcollection
Returns a CollectionInstance. For instance:
import Starlight from '@starlightcms/js-sdk'
const response = await Starlight.collection('featured-posts').items()See CollectionInstance for more info.
Type parameters
- T: unknown
The type of entity this Collection holds. You can pass this type parameter to correctly type the response of the CollectionInstance.items method.
Parameters
externalslug: string | number
Returns CollectionInstance<T>
- T: unknown
externalmodel
Returns a DynamicModelInstance, which is a ModelInstance with support for creating ModelCategoryInstances using the dynamic syntax. For instance:
import Starlight from '@starlightcms/js-sdk'
const response = await Starlight.model('posts').entries.list()See DynamicModelInstance for more info.
Type parameters
- S: string | number | symbol
Parameters
externalslug: S
Returns DynamicModelInstance<D[S]>
Other Methods
externalconfigure
Updates the client configuration. See StarlightConfig to see all the available options.
If you want to use the default SDK client, you need to set its workspace using this method in your application. You should run this method only once, and as soon as possible in your application lifecycle. For instance, when using React:
// src/index.js
import { createRoot } from "react-dom/client"
import Starlight from '@starlightcms/js-sdk'
import MyApp from './MyApp.js'
// We only need to run this once. In this case, we're
// running it before initializing our React app.
Starlight.configure({
workspace: '1234567890'
})
const rootElement = document.getElementById("root")
const root = createRoot(rootElement)
root.render(<MyApp />)Parameters
externalconfig: StarlightConfig
A configuration object. See StarlightConfig to view all available options.
Returns void
externalget
Returns a Promise that results in a response or throws a StarlightError. The response will be the parsed JSON data sent by the API.
This method is used internally by all Selectors and Instances to request data to Starlight’s Query API, but it can also be used standalone if desired.
This method automatically prefixes the given path with the API URL, but it doesn’t include a trailing slash, so be sure to include one at the start of your path.
Type parameters
- T = Record<string, unknown>
The shape of the expected response on success. Client methods generally pass StarlightItemResponse or StarlightListResponse types here.
Parameters
externalpath: string
The path to GET. Will be prefixed with the API URL. Must start with a forward slash (/).
externaloptionalparams: Record<string, undefined | string | number | boolean>
An optional object of values that will be converted to a string and passed as GET params.
externaloptionaloptions: RequestInit
An optional configuration object passed to the fetch method. Check MDN documentation on fetch to see the available options.
Returns Promise<T>
- T = Record<string, unknown>
The Starlight client is the main entry point for any requests you might want to make to Starlight’s APIs.
There’s two ways of interacting with a client: using the default client exported by the SDK or creating a new client instance using the makeStarlightClient function. Follow the provided links to learn how to use each method.
Either way you choose to interact, all clients expose the same methods and accessors that provide ways to request data. These methods and accessors return Selector or Instance objects, which are documented in the sections of the same name found in this API’s sidebar.