CWA 2 is a prerelease (2.0.0-alpha), heading for a beta. It runs production sites; configuration can still change between releases, always with upgrade notes. View versions and support
Utilities

useCwaResourceEndpoint

Resolves the correct API endpoint URL for a resource, accounting for draft/published state in admin edit mode.

useCwaResourceEndpoint gives you the API URL for a resource, with the ?published= query the current admin view needs.

import { useCwaResourceEndpoint } from '#imports'

const { endpoint, query } = useCwaResourceEndpoint(iri)
// endpoint.value → '/component/titles/018e-…?published=true'
// query.value    → '?published=true' (or '')

It returns an object, not a bare ref. Use it when you need to make manual API requests that respect the current publish state — for example fetching additional data for a resource that isn't automatically loaded by the resource store.

Signature

useCwaResourceEndpoint(iri: Ref<string | undefined>, postfix?: string)

Parameters

ParameterTypeDescription
iriRef<string | undefined>The resource IRI
postfixstring?Optional path postfix appended before the query string (e.g. '/upload')

Return Values

ReturnTypePurpose
endpointComputedRef<string>IRI + optional postfix + publish query
queryComputedRef<string>Just the query string — append it to a URL you already have (this is how withFile() and useCwaFileField suffix media URLs)

The Publish Query

A published flag is only added when the resource is publishable and the loaded version is the published one:

  • ?published=true when the admin is not editing, or when the admin has forced the live version via the Publish tab's preview toggle (forcePublishedVersion)
  • ?published=false when editing with that toggle explicitly set to the draft

Everything else — a non-publishable resource, or a draft while editing — gets the bare IRI.

Example

const props = defineProps<IriProp>()
const { endpoint } = useCwaResourceEndpoint(toRef(props, 'iri'))

const { data } = await useFetch(endpoint)

Used internally by withFile() and useCwaFileField (to suffix media URLs), useCwaResourceModel (the PATCH target) and useCwaResourceUpload (the upload and delete targets). Reach for it directly only when you are making your own API calls for a resource and need them to respect the current publish state.