0.1.2 • Published 6 months ago

@thomasravnholt/umbracoclient v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

What is UmbracoClient

UmbracoClient is a JavaScript package providing a convenient interface for interacting with the Umbraco Content Delivery API. It supports various operations such as fetching content by ID, name, route, content type, or multiple IDs, as well as media fetching capabilities. It also offers customizable query parameters for sorting, filtering, expanding, language selection, and more.

Installation

npm i @thomasravnholt/umbracoclient

Setup

Import createUmbracoClient from the package:

import { createUmbracoClient } from '@thomasravnholt/umbracoclient';

Create an instance of the client:

const umbracoClient = createUmbracoClient(
    'https://your-umbraco-domain.com',
    'your-optional-api-key'
);

Usage

Fetch Content by ID

umbracoClient.getContentById('content-id', options).then((data) => console.log(data));

Fetch Multiple Contents by IDs

umbracoClient.getContentByIds(['id1', 'id2'], options).then((data) => console.log(data));

Fetch Content by Name

umbracoClient.getContentByName('content-name', options).then((data) => console.log(data));

Fetch Content by Route

umbracoClient.getContentByRoute('content-route', options).then((data) => console.log(data));

Fetch Content by Type

umbracoClient.getContentByType('content-type', options).then((data) => console.log(data));

Fetch Media by ID

umbracoClient.getMediaById('media-id', options).then((data) => console.log(data));

Fetch Media by Path

umbracoClient.getMediaByPath('media-path', options).then((data) => console.log(data));

Fetch Media Items

umbracoClient.getMediaItems(options).then((data) => console.log(data));

Options

Customize requests using options:

  • sort: Define sorting order and type.
  • expand: Specify properties to expand in the response.
  • filter: Apply filters to the content or media.
  • language: Request content or media in a specific language.
  • preview: Fetch unpublished content or media (requires API key).
  • fetch: Options like 'ancestors', 'children', or 'descendants' for content.
  • fetchIdOrPath: ID or path for fetch operations.
  • skip: Number of items to skip (for pagination).
  • take: Number of items to take (for pagination).

Example

Fetch blog posts sorted by creation date in descending order:

const options = {
    sort: { type: 'createDate', order: 'desc' },
    expand: ['property1', 'property2'],
    filter: 'contentTypeAlias',
    language: 'en-US',
    preview: true,
    skip: 0,
    take: 10
};

umbracoClient.getContentByType('blogPost', options).then((data) => console.log(data));

Replace placeholders like 'your-umbraco-domain.com' and 'content-id' with actual values relevant to your Umbraco instance.

0.1.2

6 months ago

0.2.1

6 months ago

0.2.0

6 months ago

0.1.1

6 months ago

0.1.0

6 months ago

0.0.11

6 months ago

0.0.10

6 months ago

0.0.9

6 months ago

0.0.8

6 months ago

0.0.7

6 months ago

0.0.6

6 months ago

0.0.5

6 months ago

0.0.4

6 months ago

0.0.3

6 months ago

0.0.2

6 months ago

0.0.1

6 months ago