# JavaScript

### Installation

#### NPM

Run this command:

```bash
npm install comfortable-javascript
```

#### For Usage in Browser

```markup
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/comfortable-javascript@latest/dist/comfortable.min.js"></script>
```

> **Note:** For a specific version replace `@latest` with the version of your choice.

The SDK will be available as a global variable called: `Comfortable`

#### **Downloadable version**

Check out the release Page: <https://github.com/cmftable/comfortable-javascript/releases>

### Include the dependency

```javascript
const Comfortable = require('comfortable-javascript');
```

### Connect to your Repository and make your first request:

```javascript
const api = Comfortable.api('<repository-api-id>', '<api-key>', options);

api.getDocuments()
  .then(result => {
    // futher implementation
  })
  .catch(err => {
    throw err;
  })
```

list of **options** can be found [here](/sdk/javascript.md#options).

**Full Query example**

```javascript
const api = Comfortable.api('<repository-api-id>', '<api-key>', options);

api.getDocuments({
  limit: 25,
  offset: 0,
  locale: 'en',
  includes: 2,
  includeTags: ['include', 'me'],
  excludeTags: ['exclude', 'this'],
  fields: 'meta,fields(title)',
  embedAssets: true,
  filters: new Comfortable.Filter()
    .addAnd('title', 'like', '%Hello%')
    .addOr('title', 'like', '%World%'),
  sorting: new Comfortable.Sorting()
    .add('date', 'asc')
    .add('title', 'asc'),
  search: 'sport -football +soccer'
})
  .then(result => {
    // futher implementation
  })
  .catch(err => {
    throw err;
  })
```

### Options

| Option   | Type    | Description                                                                     |
| -------- | ------- | ------------------------------------------------------------------------------- |
| useProxy | boolean | enables the usage of a Proxy Endpoint instead of using <https://api.cmft.io/v1> |
| proxy    | string  | Proxy Url (e.g. <https://custom-api.com/v1>)                                    |


---

# 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://docs.comfortable.io/sdk/javascript.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.
