@paraswap/subscription-service-client

Simple client for Http-Subscription-Service

Usage no npm install needed!

<script type="module">
  import paraswapSubscriptionServiceClient from 'https://cdn.skypack.dev/@paraswap/subscription-service-client';
</script>

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}`);
        },
      );
});