Functions
createCraftUrl
Learn how to use the createCraftUrl function.
This function provides a simple way to build urls to query from your Craft CMS Backend. It leverages js-craftcms-api to build query URLs.
Element Types
// url for addresses query
const url = createCraftUrl('addresses').id(1).buildUrl('one')
// url for assets query
const url = createCraftUrl('assets').id(1).buildUrl('one')
// url for entry query
const url = createCraftUrl('entries').id(1).buildUrl('one')
// url for users query
const url = createCraftUrl('users').id(1).buildUrl('one')
Generate URL
By using the one
or the all
as function parameters of the buildUrl()
method you can build the url.
const query = createCraftUrl('entries').section('news')
// Generates a url to fetch one entry
const url = query.buildUrl('one')
// Generates a url to fetch all entries
const url = query.buildUrl('all')
Available Methods
createCraftUrl
supports all methods from js-craftcms-api.
Note
For the full list of available methods, see the documentation here.
In addition, the following React-specific methods are available:
Method | Description | Type |
---|---|---|
buildUrl | Generate an url | one or all |
Example
const url = createCraftUrl('entries')
.section('news')
.fields(['title'])
.limit(3)
.buildUrl('all')