2.0.9 • Published 1 year ago

socket-request-client v2.0.9

Weekly downloads
4
License
MIT
Repository
github
Last release
1 year 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.9

1 year ago

2.0.7

1 year ago

2.0.8

1 year ago

2.0.6

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.5

2 years ago

2.0.4

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.7.5

2 years ago

1.7.4

2 years ago

1.7.3

3 years ago

1.7.2

3 years ago

1.7.1

3 years ago

1.7.0

3 years ago

1.6.3

3 years ago

1.6.2

3 years ago

1.6.1

3 years ago

1.6.0

3 years ago

1.5.0

5 years ago

1.4.4

5 years ago

1.4.3

5 years ago

1.4.2

5 years ago

1.4.1

5 years ago

1.4.0

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago

0.8.1

6 years ago

0.8.0

6 years ago

0.7.2

6 years ago

0.7.1

6 years ago

0.7.0

6 years ago

0.6.3

6 years ago

0.6.2

6 years ago

0.6.1

6 years ago

0.6.0

6 years ago

0.5.1

7 years ago

0.4.2

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago