Comment on page
Getting Started
How to get the library up and running in your project.
The library has been configured to work in multiple environments:
- UMD (Browser, client-side applications)
- ESM (Browser, client-side applications)
- CJS (Server-side applications)
For browser-based applications you can link the UMD package directly from unpkg.com in a
script
tag.<script src="https://unpkg.com/@xapi/xapi"></script>
<script type="text/javascript">
// Create LRS connection
const endpoint = "https://my-lms.com/endpoint";
const username = "username";
const password = "password";
const auth = XAPI.toBasicAuth(username, password);
const xapi = new XAPI({
endpoint: endpoint,
auth: auth
});
// Create your statement
const myStatement = { ... };
// Send your statement
xapi.sendStatement({
statement: myStatement
});
</script>
For client-side applications built using imports, an ES Module is available for you to install and
import
into your project.npm i @xapi/xapi --save
import XAPI, { Statement } from "@xapi/xapi";
// Create LRS connection
const endpoint = "https://my-lms.com/endpoint";
const username = "username";
const password = "password";
const auth = XAPI.toBasicAuth(username, password);
const xapi: XAPI = new XAPI({
endpoint: endpoint,
auth: auth
});
// Create your statement
const myStatement: Statement = { ... };
// Send your statement
xapi.sendStatement({
statement: myStatement
});
For server-side applications built using require, a CommonJS module is available for you to install and
require
into your project.npm i @xapi/xapi --save
const XAPI = require("@xapi/xapi");
const endpoint = "https://my-lms.com/endpoint";
const username = process.env.LRS_USERNAME || "";
const password = process.env.LRS_PASSWORD || "";
const auth = XAPI.toBasicAuth(username, password);
const xapi = new XAPI({
endpoint: endpoint,
auth: auth
});
// Create your statement
const myStatement = { ... };
// Send your statement
xapi.sendStatement({
statement: myStatement
});
Alternatively, the module can also be imported using
.mjs
.import XAPI from "@xapi/xapi";
const endpoint = "https://my-lms.com/endpoint";
const username = process.env.LRS_USERNAME || "";
const password = process.env.LRS_PASSWORD || "";
const auth = XAPI.toBasicAuth(username, password);
const xapi = new XAPI({
endpoint: endpoint,
auth: auth
});
// Create your statement
const myStatement = { ... };
// Send your statement
xapi.sendStatement({
statement: myStatement
});
Last modified 2yr ago