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)

UMD (Browser, client-side applications)

For browser-based applications you can link the UMD package directly from unpkg.com in a script tag.
1
<script src="https://unpkg.com/@xapi/xapi"></script>
2
3
<script type="text/javascript">
4
// Create LRS connection
5
const endpoint = "https://my-lms.com/endpoint";
6
const username = "username";
7
const password = "password";
8
const auth = XAPI.toBasicAuth(username, password);
9
const xapi = new XAPI({
10
endpoint: endpoint,
11
auth: auth
12
});
13
14
// Create your statement
15
const myStatement = { ... };
16
17
// Send your statement
18
xapi.sendStatement({
19
statement: myStatement
20
});
21
</script>
Copied!

ES Module (Browser, client-side applications)

For client-side applications built using imports, an ES Module is available for you to install and import into your project.
1
npm i @xapi/xapi --save
Copied!
1
import XAPI, { Statement } from "@xapi/xapi";
2
3
// Create LRS connection
4
const endpoint = "https://my-lms.com/endpoint";
5
const username = "username";
6
const password = "password";
7
const auth = XAPI.toBasicAuth(username, password);
8
const xapi: XAPI = new XAPI({
9
endpoint: endpoint,
10
auth: auth
11
});
12
13
// Create your statement
14
const myStatement: Statement = { ... };
15
16
// Send your statement
17
xapi.sendStatement({
18
statement: myStatement
19
});
Copied!

CJS (Server-side applications)

For server-side applications built using require, a CommonJS module is available for you to install and require into your project.
1
npm i @xapi/xapi --save
Copied!
1
const XAPI = require("@xapi/xapi");
2
3
const endpoint = "https://my-lms.com/endpoint";
4
const username = process.env.LRS_USERNAME || "";
5
const password = process.env.LRS_PASSWORD || "";
6
const auth = XAPI.toBasicAuth(username, password);
7
const xapi = new XAPI({
8
endpoint: endpoint,
9
auth: auth
10
});
11
12
// Create your statement
13
const myStatement = { ... };
14
15
// Send your statement
16
xapi.sendStatement({
17
statement: myStatement
18
});
Copied!
Alternatively, the module can also be imported using .mjs.
1
import XAPI from "@xapi/xapi";
2
3
const endpoint = "https://my-lms.com/endpoint";
4
const username = process.env.LRS_USERNAME || "";
5
const password = process.env.LRS_PASSWORD || "";
6
const auth = XAPI.toBasicAuth(username, password);
7
const xapi = new XAPI({
8
endpoint: endpoint,
9
auth: auth
10
});
11
12
// Create your statement
13
const myStatement = { ... };
14
15
// Send your statement
16
xapi.sendStatement({
17
statement: myStatement
18
});
Copied!
Last modified 1mo ago