The CWA is in heavy development
The CWA is still in alpha and not ready for production - some code and implementations are likely to change. If you would like to try out the CWA, please enjoy what we have provided and feel free to provide feedback, or get involved on GitHub.
DraftUtilities

useCwaResourceEndpoint

Resolves the correct API endpoint URL for a resource, accounting for draft/published state in admin edit mode.
import { useCwaResourceEndpoint } from '#imports'

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

useCwaResourceEndpoint 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.

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
queryRef<string>Just the query string — append it to a URL you already have (this is what useCwaFile does for 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 useCwaFile/withFile (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.