crs-client
TypeScript icon, indicating that this package has built-in type declarations

2.0.0-alpha.9 • Public • Published

crs-client

The JavaScript client library for crs

Installaion

npm install crs-client --save

Usage

Typescript / ESNext

import { CrsEndpoint, Command } from 'crs-client';
 
// Create a command class and bound to a CRS commmand
@Command('supercommand')
class SuperCommand {
    constructor(hello) {
        this.hello = hello;
    }
}
 
// create a new endpoint where {server url} is your server URL (empty is same origin) 
// and {crs endpoint} is the path to the CRS endpoint
const endpoint = new CrsEndpoint('{server url}/{crs endpoint}');
 
// initialize the endpoint
endpoint.connect();
 
// send the command
emitter.send(new SuperCommand('hello world!'))
    .then(response => {
        console.log(response);
    });

ES5 in browser

First, include the library crs-client.js in your HTML

<script src="crs-client.js"></script>

The script will add the Crs object on the window object.

// Specify the command name. 
Crs.Command('supercommand')(SuperCmd)
function SuperCmd(hello) {
    this.hello = hello;
}
 
// create a new endpoint
var endpoint = new Crs.CrsEndpoint('{server url}/{crs endpoint}');
 
// initialize the endpoint
endpoint.connect();
 
// send the command
const response = await endpoint.send(new SuperCmd('hello world!'));

Readme

Keywords

none

Package Sidebar

Install

npm i crs-client

Weekly Downloads

1

Version

2.0.0-alpha.9

License

ISC

Unpacked Size

3.04 MB

Total Files

99

Last publish

Collaborators

  • shabs