primus-requests
Version:
Send named requests and receive responses with primus
51 lines (32 loc) • 875 B
Markdown
Send a named request with data and attach a callback to get the response.
```bash
npm install primus-requests --save
```
After installing with npm add primus-requests as a [primus plugin](https://github.com/primus/primus#plugins)
```
{
transformer: ...,
plugin: {
requests: require('primus-requests')
}
}
```
Sending requests is identical on the server and the client.
```
(primus || spark).send('message', 'hello', (data) => {
// Do something with the response in data
})
```
Responding to requests is also identical on the server and client.
```
(primus || spark).on('hello', (data, response) => {
// Data is what is sent with the request
// Response is a callback to send data back
response('Well hey there')
})
```