A client library for retrieving content from Kentico Cloud that supports JavaScript and TypeScript.
Visit this wiki page to see how you can use this SDK in Node.js environment.
npm i kentico-cloud-delivery-typescript-sdk --save
import { ContentItem, Fields } from 'kentico-cloud-delivery-typescript-sdk';
/**
Each content type needs to have model class
*/
export class Movie extends ContentItem {
public title: Fields.TextField;
}
/**
* Type resolvers make sure instance of proper class is created for your content types
*/
let typeResolvers: TypeResolver[] = [
new TypeResolver('movie', () => new Movie()),
];
/**
* Create new instance of Delivery Client
*/
var deliveryClient = new DeliveryClient(
new DeliveryClientConfig('projectId', typeResolvers)
);
/**
* Get data from Cloud
*/
deliveryClient.items<Movie>()
.type('movie')
.get()
.subscribe(response => {
console.log(response);
// you can access strongly types properties
console.log(response.items[0].title.text);
});
var KenticoCloud = require('kentico-cloud-delivery-typescript-sdk');
/**
Each content type needs to have model class
*/
class Movie extends KenticoCloud.ContentItem {
constructor() {
super();
}
}
/**
* Type resolvers make sure instance of proper class is created for your content types
*/
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
*/
deliveryClient.items()
.type('movie')
.get()
.subscribe(response => console.log(response));
- Use
npm test
to run all tests. - Use
npm run dev-test
to run developer tests created indev-test
folder. Use this for your testing purposes. - Use
npm run nodejs-test
runs Node.js application and checks if response was successful - Use
npm run build
to generate definitions & dist from the contents oflib
folder. - Use
npm run coveralls
to push coverage data directly to https://coveralls.io. Can be executed only after runningnpm test
.
Feedback & Contributions are welcomed. Feel free to take/start an issue & submit PR.