2.0.8 • Published 7 days ago

socket-request-client v2.0.8

Weekly downloads
4
License
MIT
Repository
github
Last release
7 days ago

socket-request-client

server <-> client connection with ease

INSTALL

npm i --save socket-request-client

USAGE

import {SocketRequestClient} from 'socket-request-client';
const request = {url: 'user', params: {password: 'password', email: 'email'}};

const client = new SocketRequestClient('ws://localhost:4000')
const connection = await client.init()
// a request is client.on & client.send combined
const requested = await connection.request(request);
// or
client.clientConnection.request(request)

custom pubsub

import {SocketRequestClient} from 'socket-request-client';
import IpfsApi from 'ipfs-api';
const ipfs = new IpfsApi();

const request = {url: 'user', params: {password: 'password', email: 'email'}};

const client = new SocketRequestClient('ws://localhost:4000', 'echo-protocol', {
  pubsub: ipfs.pubsub,
  retry: false
})
const connection = await client.init()
connection.on('send', result => { console.log(result) })
connection.send(request);
  

API

socketRequestClient(options)

send

request.url request.params: Object

client.send(request)

request

request.url request.params: Object returns: Promise

await client.request(request)

subscribe (local pubsub)

name: name of the channel to subscribe to handler: method context: context

client.subscribe('event-name', data => {
  console.log(data);
})

unsubscribe (local pubsub)

name: name of the channel to unsubscribe handler: method context: context

client.unsubscribe('event-name', data => {
  console.log(data);
})

publish (local pubsub)

name: name of the channel to publish to handler: method context: context

client.publish('event-name', 'data')

uptime

await client.uptime()

pubsub.subscribe

name: name of the channel to subscribe to handler: method context: context

client.pubsub.subscribe('event-name', data => {
  console.log(data);
})

pubsub.unsubscribe

name: name of the channel to unsubscribe handler: method context: context

client.pubsub.unsubscribe('event-name', data => {
  console.log(data);
})

pubsub.publish

name: name of the channel to publish to handler: method context: context

client.pubsub.publish('event-name', 'data')

pubsub.subscribers

client.pubsub.subscribers()

server.uptime

returns: Promise

await client.server.uptime()

server.ping

returns: Promise

await client.server.ping()
2.0.7

7 days ago

2.0.8

7 days ago

2.0.6

7 months ago

2.0.3

11 months ago

2.0.2

11 months ago

2.0.5

11 months ago

2.0.4

11 months ago

2.0.1

11 months ago

2.0.0

11 months ago

1.7.5

1 year ago

1.7.4

1 year ago

1.7.3

1 year ago

1.7.2

1 year ago

1.7.1

1 year ago

1.7.0

1 year ago

1.6.3

2 years ago

1.6.2

2 years ago

1.6.1

2 years ago

1.6.0

2 years ago

1.5.0

4 years ago

1.4.4

4 years ago

1.4.3

4 years ago

1.4.2

4 years ago

1.4.1

4 years ago

1.4.0

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago

0.8.1

5 years ago

0.8.0

5 years ago

0.7.2

5 years ago

0.7.1

5 years ago

0.7.0

5 years ago

0.6.3

5 years ago

0.6.2

5 years ago

0.6.1

5 years ago

0.6.0

5 years ago

0.5.1

6 years ago

0.4.2

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago