Skip to content

MartinaFarkasova/KenticoCloudDeliveryTypeScriptSDK

 
 

Repository files navigation

Kentico Cloud Delivery JavaScript / TypeScript SDK

npm version Build Status npm Forums Coverage Status Known Vulnerabilities Dependency Status

A client library for retrieving content from Kentico Cloud that supports JavaScript and TypeScript.

TypeScript

JavaScript

DocumentationDocumentation
Quick startQuick start
Sample apps
Angular 4 app JavaScript app
API documentation
Get items (Observable)Get items (Observable)
Get items (Promise)Get items (Promise)
Creating modelsCreating models
Model generatorModel generator
Initialize clientInitialize client
Query parametersQuery parameters
FilteringFiltering
SortingSorting
LocalizationLocalization
Property binding / Model decoratorsProperty binding
Preview modePreview mode
URL slugsURL slugs
Rich text resolverRich text resolver
Strongly typed nested propertyN/A
Get typesGet types
Get taxonomiesGet taxonomies
Errors
Handling errorsHandling errors
Debugging
Request dataRequest data
Getting URLGetting URL

Node.js support

Visit this wiki page to see how you can use this SDK in Node.js environment.

Quick start

npm i kentico-cloud-delivery-typescript-sdk --save

TypeScript (ES6)

import { ContentItem, Fields,TypeResolver,DeliveryClient,DeliveryClientConfig } from 'kentico-cloud-delivery-typescript-sdk';

/**
 * This is optional, but it is considered a best practice to define your models
 * so you can leverage intellisense and so that you can extend your models with 
 * additional properties / methods.
 */
export class Movie extends ContentItem {
  public title: Fields.TextField;
}

/**
 * Type resolvers make sure instance of proper class is created for your content types.
 * If you don't use any custom models, return an empty array.
 */
let typeResolvers: TypeResolver[] = [
    new TypeResolver('movie', () => new Movie()),
];

/**
 * Create new instance of Delivery Client
 */
var deliveryClient = new DeliveryClient(
  new DeliveryClientConfig('projectId', typeResolvers)
);

/**
 * Get typed data from Cloud (note that the 'Movie' has to be registered in your type resolvers)
 */
deliveryClient.items<Movie>()
  .type('movie')
  .get()
  .subscribe(response => {
    console.log(response);
    // you can access strongly types properties
    console.log(response.items[0].title.text);
});

/**
 * Get data without having custom models 
 */
deliveryClient.items<ContentItem>()
  .type('movie')
  .get()
  .subscribe(response => {
    console.log(response);
    // you can access properties same way as with strongly typed models, but note
    // that you don't get any intellisense and the underlying object 
    // instance is of 'ContentItem' type
    console.log(response.items[0].title.text);
});

JavaScript (CommonJS)

var KenticoCloud = require('kentico-cloud-delivery-typescript-sdk');

/**
 * This is optional, but it is considered a best practice to define your models
 * so that you can leverage intellisense and extend your models with 
 * additional methods.
 */
class Movie extends KenticoCloud.ContentItem {
    constructor() {
        super();
    }
}

/**
 * Type resolvers make sure instance of proper class is created for your content types.
 * If you don't use any custom classes, return an empty array.
 */
var typeResolvers = [
    new KenticoCloud.TypeResolver('movie', () => new Movie()),
];

/**
 * Delivery client configuration object
 */
var config = new KenticoCloud.DeliveryClientConfig(projectId, typeResolvers);

/**
 * Create new instance of Delivery Client
 */
var deliveryClient = new KenticoCloud.DeliveryClient(config);

/**
 * Fetch all items of 'movie' type and given parameters from Kentico Cloud.
 * Important note: SDK will convert items to your type if you registered it. For example,
 * in this case the objects will be of 'Movie' type we defined above. 
 * If you don't use custom models, 'ContentItem' object instances will be returned.
 */
deliveryClient.items()
    .type('movie')
    .get()
    .subscribe(response => console.log(response));

Scripts

  • Use npm test to run all tests.
  • Use npm run dev-test to run developer tests created in dev-test folder. Use this for your testing purposes.
  • Use npm run nodejs-test to test HTTP response in Node.js application.
  • Use npm run build to generate definitions & dist from the contents of lib folder.
  • Use npm run coveralls to push coverage data directly to https://coveralls.io. Can be executed only after runningnpm test.
  • Use npm run prepublish-test to run all tests required before publishing new version without actually increasing version.

Publish scripts

  • Use npm run publish-patch to run all tests, increase patch version and publish it to NPM.
  • Use npm run publish-minor to run all tests, increase minor version and publish it to NPM.
  • Use npm run publish-major to run all tests, increase major version and publish it to NPM.

Feedback & Contribution

Feedback & Contributions are welcomed. Feel free to take/start an issue & submit PR.

About

Kentico Cloud Delivery TypeScript SDK

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 97.4%
  • JavaScript 2.6%