@paraswap/subscription-service-client
v1.0.3
Published
> Simple client for [Http-Subscription-Service](https://github.com/paraswap/http-subscription-service)
Downloads
257
Keywords
Readme
Subscription-service-client
Simple client for Http-Subscription-Service
Table of Contents
Install
Install the package from NPM:
npm install @paraswap/subscription-service-client
Usage
import { HttpSubscriptionService } from '@paraswap/subscription-service-client;
// Create na instance
const client = new HttpSubscriptionService(HTTP_SUBSCRIPTION_SERVICE_WS_URL)
// Subscribe for connection event (this event will be triggered as soon as we get a connection to the `http-subscription-service`)
client.on('opened', () => {
// Create a subscription
HttpSubscriptionService.subscribe(
{
pollInterval: 5000, // Provide a polling interval for your subscription
requestOptions: { // Request options (AxiosRequestOptions)
url: `test.com/getWeather`
},
},
(state: { data: WeatherResponse }) => { // Callback for data
console.log(`Current temp: ${weather.temp}`);
},
);
});