UNPKG

@smapiot/piral-cloud-browser

Version:

Piral Cloud: Browser-usable API Client for the Piral Feed Service.

80 lines (50 loc) 2.14 kB
[![Piral Logo](https://github.com/smapiot/piral/raw/main/docs/assets/logo.png)](https://piral.io) # `@smapiot/piral-cloud-browser` Browser-usable API Client for the [Piral Feed Service](https://www.piral.cloud). This package works in any environment supporting `fetch` and handling ESMs (e.g., bundlers, modern browsers, ...). ## Important Links * 📢 **[We are hiring!](https://smapiot.com/jobs)** - work with us on Piral, its ecosystem and our users * 🌍 [Website](https://www.piral.cloud/) - learn more about the Piral Feed Service * 📖 [Documentation](https://docs.piral.cloud/) - everything to get started and master the Piral Feed Service * 👪 [Community Chat](https://gitter.im/piral-io/community) - ask questions and provide answers in our Gitter room ## Installation The package can be installed with your favorite npm client, e.g.: ```sh npm i @smapiot/piral-cloud-browser ``` Once installed the package is ready to be used. ## Usage To use the package you need to import the `createServiceClient` function and call it: ```js import { createServiceClient } from '@smapiot/piral-cloud-browser'; const client = createServiceClient({ apiKey: '123...', }); // use the client ``` If you want to use it with your own Piral Feed Service instance then provide the `host` option: ```js import { createServiceClient } from '@smapiot/piral-cloud-browser'; const client = createServiceClient({ apiKey: '123...', host: 'http://localhost:9000', }); // use the client ``` ## Example If you want to just manipulate a feed you can go ahead and use the `doUpdateFeed` function. ```js import { createServiceClient } from '@smapiot/piral-cloud-browser'; const client = createServiceClient({ apiKey: '123...', }); const feedId = 'my-feed'; console.log('Before', await client.doQueryFeed(feedId)); await client.doUpdateFeed(feedId, { contributors: ['a@b.com', 'c@d.com'], }); console.log('After', await client.doQueryFeed(feedId)); ``` Everything is fully typed using TypeScript declarations. ## License This SDK is released using the MIT license. For more information see the [license file](./LICENSE).