1.0.3 • Published 2 years ago

@mantil-io/mantil.js v1.0.3

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

mantil.js

mantil.js is a JavaScript SDK for developing Mantil applications.

Instalation

npm install @mantil-io/mantil.js

Using the WebSocket API

Using this SDK we can easily connect to a WebSocket endpoint of a mantil project.

To connect, use the createWsApi method:

import { createWsApi } from '@mantil-io/mantil.js';

const api = createWsApi();

This will attempt to find the API URL using the global variable mantilEnv (see here). Mantil will add a mantil_env.js script which defines this variable to the root of every deployed static website, so you can just include it in your public/index.html file:

<script type="text/javascript" src="/mantil_env.js"></script>

Alternatively, you can pass a custom URL to the createWsApi function:

const api = createWsApi('wss://...');

Now you can use the api object to: 1. Subscribe to subjects:

api.subscribe('subject', message => console.log(message));
  1. Invoke api methods:
const rsp = await api.request('ping.default');
console.log(rsp);

This will invoke the default method of the ping API.

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago