> For the complete documentation index, see [llms.txt](https://docs.elentra.org/ejs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.elentra.org/ejs/1.2/guide/plugins/core-plugins/instance-objects/usdapi.md).

# $api

## Introduction

The **$api** instance object provides access to a shared instance of the EJS [REST Client](/ejs/1.2/guide/http-library/rest-client.md) to be available across [components](/ejs/1.2/guide/modules/components.md).  This instance is created before any [modules](/ejs/1.2/guide/modules.md) are loaded and is [configured](/ejs/1.2/guide/environments/configuration.md) using the `apiPath` [directive](/ejs/1.2/guide/environments/configuration.md#directives) from the [environment](/ejs/1.2/guide/environments.md)'s configuration file.

{% hint style="warning" %}
The `apiPath` directive is relative to the current host origin.  Cross-origin API requests are currently not allowed and will be rejected, throwing a `Http/NetworkError`.
{% endhint %}

The **$api** object allows you to make API requests without importing or instantiating REST Client.  In addition, this enables the environment to fully manage the API authorization process, including the initial seed token.

## Enabling the $api instance object

The **$api** instance object can be enabled across an application by including it in the `Plugin` [namespace ](/ejs/1.2/guide/environments/namespaces.md)and adding the related entry to the [environment configuration](/ejs/1.2/guide/environments/configuration.md) file.

In this example, the environment will expect to find the [plugin](/ejs/1.2/guide/plugins.md) class at:\
`Plugin/Vue/InstanceMethod/Api.js`.

{% code title="environment.js" %}

```javascript
...
plugins: [
    'Vue/InstanceMethod/Api'
]
...
```

{% endcode %}

## Usage

The **$api** instance object is an instance of [REST Client](/ejs/1.2/guide/http-library/rest-client.md), so its interface is the same.

{% code title="MyComponent.vue" %}

```javascript
this.$api.get('/path/to/endpoint').then(response => {
    let result = response.json();
});
```

{% endcode %}
