Introducing the Textile Javascript Client

Supercharge your desktop and browser apps with Textile

We’re proud to introduce the Textile Javascript Client, a brand new open source client library that lets developers harness the power of Textile in desktop and browser-based web-apps. We mentioned @textile/js-http-client briefly in a recent post about Textile on desktop, but since then, the library has received some major updates, and has already been downloaded over 500 times! New features include a full re-write in Typescript, a bunch of new, fully-isomorphic APIs, plus some extremely powerful streaming endpoints (featuring ReadableStreams in both Nodejs and the browser). We’ve also reduced the library size and made it easier to install on Nodejs (requires fewer crypto dependencies), and added webpack support for easy deploying to browser apps (plus it works great with React and other web frameworks). Available on npm now!

Brief rundown of the library

Textile provides encrypted, recoverable, schema-based, and cross-application data storage built on IPFS and libp2p. We like to think of it as a decentralized data wallet with built-in protocols for sharing and recovery, or more simply, an open and programmable iCloud. The reference implementation of Textile is written in Go, and can be compiled to various platforms, including mobile (Android/iOS) and desktop/server (OSX, Windows, Linux, etc). The js-http-client library is designed to help support things like browser-based Textile apps, Nodejs apps, and other use-cases.

Essentially, js-http-client provides access to an underlying go-textile node's REST API, adding various simplified APIs to support in-browser and and desktop (Nodejs, Electron, etc) access. For the most part, you get all the goodness you get from all the other APIs (command-line, mobile, etc), with some browser-specific enhancements/super-powers!

It’s easy to get going

The easiest way to install and start interacting with Textile from Javascript is by downloading and installing the Textile tray app, and then interfacing with it via js-http-client. To do this, simply add the client to your project’s dependencies:

yarn add @textile/js-http-client

And start building! Here’s a quick demo to add blob data (in this case, mp3 data) to Textile/IPFS so that any peers subscribed to your thread well get an update.

import textile from '@textile/js-http-client'
import * as fs from 'fs'
import * as path from 'path'

// Here you'd probably query for an existing thread
// or create a new one and invite peers to join you
const thread = await textile.threads.add(
  'New Thread', 'blob', 'blob.key-v0.0.1', 'private', 'invite_only'
)
const file = path.resolve(__dirname, './music.mp3')
const data = await fs.readFileSync(file, { encoding: 'base64' })
// Adding structured data to IPFS/Textile is really this easy:
const added = await textile.files.add(
  data, 'hello world', thread.id
)
// Now we can check to make sure it really worked (it will)
const files = await textile.files.list()
const match = files.items.find((file) => file.block === added.block)
const status = match ? 'success' : 'failure'
console.info(`File add was a ${status}!`)

Want to see this example work for reals? Jump on over to our js-http-playground for a growing set of code recipes to do cool things with js-http-client. This is a work in progress, so if you want to see an example of how to do X with Textile in Javascript, give us a shout, we’d be happy to add it! Want still more examples? Check out our new Tour of Textile, which has code snippets for our command-line tool, and our various Textile clients (including js-http-client). Speaking of clients, here’s a nice rundown of up-to-date features and examples using the js-http-client library.

Real-world Apps

For those of you who want to skip the documentation and see the library in action, check out our Textile desktop tray app or Textile Photos for Desktop, both are built on js-http-client, and use the latest and greatest features. Follow our developments there to see how the library (and those projects) progresses.

Support & Documentation

For a “getting started” crash course, check out the examples in js-http-playground, or jump on over to our docs page. The library is moving quickly as we pull in some early feedback, but already you should find getting started takes just a few minutes. You can also read more extensively about the Textile technology both in other blog posts here or in our Tour of Textile. If you hit a roadblock, or just want to learn from others, feel free to join our community slack channel, it’s starting to buzz with people building things with Textile.

Build build build!

We’ve got a billion ideas for how you can use Textile to build cool things; from decentralized link sharing, to light-weight decentralized content clients, chat apps, and clones of Textile Photos (seriously, we encourage it!). We’re excited to release js-http-client to help bootstrap the next wave of decentralized web and desktop apps. It’s a great time to get involved and build an app. In fact, the js-http-client library itself was originally kicked off by a community project (this which was created for this)! So don’t hesitate to dig in, and let us know what you come up with, we’re always here to help.

Carson Farmer

Carson Farmer