Meet npm Pro: unlimited public & private packages + package-based permissions.Learn more »

@umbraco/headless-client

0.5.0 • Public • Published

NodeJS Client Library for Umbraco Heartcore

Umbraco Heartcore is the headless cms version of Umbraco as a service.

This repository contains the Node.js client library for the Umbraco Heartcore REST APIs.

Install

> npm install @umbraco/headless-client

Usage

Create a client, then call commands on it

 
// client.ts
import {Client} from '@umbraco/headless-client'
 
const client = new Client({
  projectAlias: 'headless-house-of-code'
})
 
client.setAPIKey(`FF00FF1133FF==`)
export default client
 
// rootLinks.ts
async function rootLinks(client: Client) {
  const rootContent = await client.delivery.content.root()
 
  const childPages = rootContent.map(child => ({
    url: child._url,
    name: child.name
  }))
 
  return childPages
}
 
function linkGenerator(links: {url: string, name: string}[]) {
  return links.map(link => {
    return `<a href="${link.url}">${link.name}</a>`
  })
}
 
async function main() {
  const rootLinks = await rootLinks(require('./client').default)
  const links = linkGenerator(rootLinks)
  console.log(links)
}
 

Available clients

All client calls will return an instance of ApiRequest class.

For fetching content the promise method must be called example below:

client.delivery.content.root()
  .then(response => {
    console.log(response)
  })

Content Delivery

Content

client.delivery.content.root()
client.delivery.content.byId(idstring)
client.delivery.content.byUrl(urlstring)
client.delivery.content.children(urlstring)
client.delivery.content.ancestors(idstring)
client.delivery.content.descendants(idstring)
 
// TS Example:
import {ContentResponseElement} from '@umbraco/headless-client'
 
client.delivery.content.root<T extends ContentResponseElement>()ApiRequest<T>

Media

client.delivery.media.root()
client.delivery.media.byId(idstring)
client.delivery.media.children(idstring)

Content Management

Content

client.management.content.root()
client.management.content.byId(idstring)
client.management.content.children(idstring)
client.management.content.create(bodyCreateContentBody)
client.management.content.publish(idstring)
client.management.content.unPublish(idstring)
client.management.content.update(idstring, bodyContentResponseElement)
client.management.content.delete(idstring)

Content Type

client.management.contentType.all()
client.management.contentType.byAlias(aliasstring)

Media

client.management.media.root()
client.management.media.byId(idstring)
client.management.media.children(idstring)
client.management.media.create(bodyany)
client.management.media.update(idstring, bodyany)
client.management.media.delete(idstring)

Media Type

client.management.mediaType.all()
client.management.mediaType.byAlias()

Language

client.management.language.all()
client.management.language.byISOCode(isoCodestring)
client.management.language.create(dataCreateContentLanguageType)
client.management.language.update(isoCodestring, dataCreateContentLanguageType)
client.management.language.delete(isoCodestring)

Relation

client.management.relation.byId(idstring)
client.management.relation.byAlias(aliasstring)
client.management.relation.byChild(idstring)
client.management.relation.byParent(idstring)
client.management.relation.create(dataany)
client.management.relation.delete(idstring)

Relation Type

client.management.relationType.byAlias(aliasstring)

Member

client.management.member.byUsername(usernamestring)
client.management.member.create(dataContentCreateMemberType)
client.management.member.update(usernamestring, dataContentCreateMemberType)
client.management.member.addGroup(usernamestring, groupNamestring)
client.management.member.removeGroup(usernamestring, groupNamestring)
client.management.member.delete(usernamestring)

Member Group

client.management.memberGroup.byName(namestring)
client.management.memberGroup.create(dataContentMemberCreateGroupType)
client.management.memberGroup.delete(namestring)

Member Type

client.management.memberType.all()
client.management.memberType.byAlias(aliasstring)

Install

npm i @umbraco/headless-client

DownloadsWeekly Downloads

8

Version

0.5.0

License

MIT

Unpacked Size

213 kB

Total Files

144

Last publish

Collaborators

  • avatar
  • avatar
  • avatar
  • avatar