SDK Quickstart

Overview

A Software Development Kit (SDK) is a code library which developers can install into their own software, to allow them to interact with third-party systems. The Core LRS SDK is available as a .Net Standard NuGet package, which can be installed into .Net applications to allow them to easily work with Core LRS without the need to understand the specifics of how the communication takes place.

The SDK is configured in only a few lines of code and can then be used for many common kinds of interactions, such as launching content, querying statements, or reading state from the database.

Getting Started

There are three main stages to adding the SDK into projects:

  1. Install the NuGet package

  2. Configure the connection

  3. Add code to interact with Core LRS using the SDK

1. Install the NuGet package

The .Net SDK is available from NuGet.org

To install from Package Manager:

Install-Package CoreLRS.SDK

2. Configure the connection

To allow the SDK to securely access Core LRS, it must be configured with a connection string. You can find your connection strings within the Core LRS Portal, under the ‘Keys’ section. A Primary and Secondary connection string is shown on this page, and it doesn’t matter which one you use.

Configuration in .Net Core Startup.cs:

using J18.CoreLRS.Sdk;

public void ConfigureServices(IServiceCollection services)
{
    ...
    // Replace with your connection string from the Core LRS Portal
    var connectionString = "ServiceName=myservice;EndpointSuffix=eu.corelrs.com;AccountKey=TXlTZWNyZXRLZXlGb3JDb3JlTFJT";
    services.AddLrsClient(connectionString);
    ...
}

Warning

For simplicity, the example above shows the connection string hard-coded into the Startup file.

As best practice, this should be obtained from a configuration variable and stored securely, since the connection string must be protected and remain confidential.

3. Add code to interact with Core LRS

Once the LRS Client is configured within startup, you can inject it into your code to use it.

For example, to query statements in the LRS:

public class StatementsController : Controller
{
    private readonly ILrsClient _lrsClient;

    public StatementsController(ILrsClient lrsClient)
    {
        // Inject the client into your code
        _lrsClient = lrsClient;
    }

    [HttpGet]
    public async Task<IActionResult> Index()
    {
        // Build a query
        var queryOptions = new StatementQueryOptions
        {
            Activity = "http://my.domain.com/modules/introduction",
            Verb = "http://adlnet.gov/expapi/verbs/launched"
        };

        // Get the results
        var response = await _lrsClient.Statements.QueryAsync(queryOptions);
        return View(response);
    }
}

You can find a complete set of samples on the Core LRS Samples repository on GitHub.