# Getting Started

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.

```markup
<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>
```

## 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.

```bash
npm i @xapi/xapi --save
```

```typescript
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
});
```

## 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.

```bash
npm i @xapi/xapi --save
```

```javascript
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`.

```javascript
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
});
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.xapijs.dev/xapi-wrapper-library/getting-started.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
