Git Product home page Git Product logo

delivery-sdk-net's Introduction

Kontent.ai Delivery .NET SDK

Build & Test codecov Stack Overflow Discord

Paradigm Package Downloads Compatibility Documentation
Async NuGet NuGet net6.0 ๐Ÿ“– Wiki
Reactive NuGet NuGet net6.0 ๐Ÿ“– Wiki

Summary

The Kontent.ai Delivery .NET SDK is a client library that lets you easily retrieve content from Kontent.ai.

Getting started

Installation via Package Manager Console in Visual Studio:

PM> Install-Package Kontent.Ai.Delivery

Installation via .NET CLI:

> dotnet add <TARGET PROJECT> package Kontent.Ai.Delivery

Usage

To retrieve content from your Kontent.ai projects, you'll be using an implementation of the IDeliveryClient interface. This is the main interface of the SDK. Here's how you can instantiate and use the Delivery client either with DI/IoC or without DI/IoC.

Use dependency injection (ideal for ASP.NET Core web apps)

Startup.cs

public void ConfigureServices(IServiceCollection services)
{
	services.AddDeliveryClient(Configuration);
}

HomeController.cs

public class HomeController
{
	private IDeliveryClient _client;

	public HomeController(IDeliveryClient deliveryClient)
	{
		_client = deliveryClient;
	}
}

In this case, the SDK reads the configuration from the DeliveryOptions section of the Configuration object. There are many ways of providing the configuration to the DeliveryClient as well as many advanced registration scenarios which you can all find in the Wiki.

To see a complete working example, go to one of our sample apps:

To spin up a fully configured blank site quickly, use the:

Usage without IoC/DI containers (ideal for console apps, unit tests...)

You can also set up a DeliveryOptions manually using the DeliveryClientBuilder.

IDeliveryClient _client = DeliveryClientBuilder
    .WithOptions(builder => builder
        .WithProjectId("<YOUR_PROJECT_ID>")
	.UseProductionApi()
	.Build())
    .Build();

Your first request

Use the .NET code generator to generate POCO models:

public class Article
{
        public string Title { get; set; }
        public string Summary { get; set; }
	public string Body { get; set; }
	public DateTime? PostDate { get; set; }
	public ContentItemSystemAttributes System { get; set; }
}

Call the IDeliveryClient to retrieve data from Kontent:

// Retrieving a single content item
var response = await _client.GetItemAsync<Article>("<article_codename>");
var title = response.Item.Title; // -> "On Roasts"
var lang = response.Item.System.Language; // -> "en-US"

See Working with Strongly Typed Models to learn how to generate models and adjust the logic to your needs.

Further information

For more developer resources, visit:

Get involved

Check out the contributing page to see the best places to file issues, start discussions, and begin contributing.

delivery-sdk-net's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.