@oneflow/loopback-component-primus
Primus adapter for loopback. It allows you to call loopback's remote methods via websocket.
Last updated 2 years ago by pieromaltese .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @oneflow/loopback-component-primus 
SYNC missed versions from official npm registry.

loopback-component-primus

Primus adapter for loopback. It allows you to call loopback's remote methods via websocket.

Getting Started

npm install --save @oneflow/loopback-component-primus

Add the loopback-component-primus component to the server/component-config.json:

"@oneflow/loopback-component-primus": {}

A small change is needed in the server/server.js file, replace:

app.start();

with:

app.server = app.start();

Usage

Call remote methods

The primus client library is exposed at the URL http://<LOOPBACK_URL>/primus/primus.js You will need to import it in your html:

<script type="text/javascript" src="http://<LOOPBACK_URL>/primus/primus.js"></script>

Then, in your code:

const primus = new Primus({
	url: 'http://<LOOPBACK_URL>',
});

Now you will be able to call remote methods using primus.send('invoke', {...});


// Call prototype method:

primus.send('invoke', {
		methodString: 'color.prototype.patchAttributes',
		args: {
			id: 1,
			data: { name: 'black' }
		},
	}, function (err, data) {
		if (err) {
			return alert('Error from server: ' + JSON.stringify(err));
		}

		alert('Record updated: ' + JSON.stringify(data));
	});
		
// Call static method:
primus.send('invoke', {
		methodString: 'color.find',
		args: {
			filter: {
				where: {
					name: 'black'
				}
			}
		},
	}, function (err, data) {
		if (err) return alert('Error from server: ' + JSON.stringify(err));
	
		alert('Find results: ' + JSON.stringify(data));
	});
Spark

You can find the spark property, in the ctx object.

Current Tags

  • 1.0.9                                ...           latest (2 years ago)

10 Versions

  • 1.0.9                                ...           2 years ago
  • 1.0.8                                ...           2 years ago
  • 1.0.7                                ...           2 years ago
  • 1.0.6                                ...           3 years ago
  • 1.0.5                                ...           3 years ago
  • 1.0.4                                ...           3 years ago
  • 1.0.3                                ...           3 years ago
  • 1.0.2                                ...           3 years ago
  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           3 years ago

Copyright 2014 - 2017 © taobao.org |