PubSub in the browser with the JS IPFS HTTP API client
by Alan Shaw on 2019-08-29
EXCELLENT NEWS! You can now pubsub with the JS IPFS HTTP API client in the BROWSER!
Due to boring technical reasons it’s previously not been possible to support pubsub over the HTTP API in the browser. Now that the fetch API supports cancelation, and has done so for a while, pubsub support has arrived! Hooray \o/
There’s also a brand new example application that you can play with showing how to use pubsub in the browser:
This was made possible by the experimentation done in a “lite” http client I was working on, which was originally meant to be just really really small (it’s currently ~13kb gzipped vs ~200kb for the regular client). To make it small we needed to switch to using the fetch API but I soon realized that this opened up a bunch of other opportunities, like enabling pubsub. We also get easily cancelable requests, request timeouts, custom fetch implementations and a switch to async/await and async iterators.
I originally demoed it in the lite client here:
The lite client has been a great proving ground for ensuring the “hard parts” of the API are now possible using browser native APIs. I’ll be applying more of the learnings from there to the regular http client in the near future, which should hopefully result in a smaller bundle size, as well as more cool new features like this one.
Version 34 of
ipfs-http-client is out now! https://www.npmjs.com/package/ipfs-http-client/v/34.0.0
Thanks for reading 😘