Webpipe.js

Javascript library for interacting with Webpipes.

Introduction

Webpipes are tiny HTTP programs that do one thing and do it well. They fill in the gaps. Need a proxy? Need to convert Markdown to HTML? Give a Webpipe some input, and it'll give you some output. They're a handy tool to have in your arsenal.

Think of Webpipes as extending your standard library over HTTP. If you're missing a library in your language of choice, there could be webpipe available instead.

Webpipe.js interacts with webpipes.org, a centralized Webpipe registry and dispatching service.

Learn more at Webpipes.org →

Setup

Just include the script. The webpipe object is automagically added to your environment. No need for new or any other sort of initialization. As a courtesy, webpipejs.org offers a CDN compressed version of the script. In the browser do the following (you can also use HTTPS):

<script src="http://cdn.webpipejs.org/0.1.2/webpipe.min.js"></script>

...or if you're working with Node.js, install webpipe.js with NPM:

$ npm -g install webpipe 

View code on GitHub →

Usage Example

Webpipe.js exposes two methods: webpipe.manual() and webpipe.request().

webpipe.manual()

This is a convenience function that returns the webpipe.json for the webpipe in question.

webpipe.manual('proxy', function (er, data) {
	if (er) {
		console.log("Error: "  + er);
	} else {
		console.log(data);
	}
});

Results in the following output:

 
		
		
		
			

webpipe.request()

The real workhorse is webpipe.request(). This allows you to make requests to any webpipe in registry.webpipes.org.

var url = "https://raw.github.com/matthewhudson/dotfiles/master/README.md";
webpipe.request('proxy', { method: "GET", url : url }, function (er, data) {
	if (er) {
		console.log("Error: "  + er);
	} else {
		console.log(data);
	}
});

Results in the following output:


		
		
					

Pulling it Together: Combining Webpipes

You can combine requests together, thus truly harnessing the power of pipes. For example, lets convert my README from Markdown to HTML.

var url = "https://raw.github.com/matthewhudson/dotfiles/master/README.md";
webpipe.request('proxy', { method: "GET", url : url }, function (er, data) {
	if (er) {
		console.log("Error: "  + er);
	} else {
		webpipe.request('markdown-to-html', { markdown : data }, function (er, data) {
			if (er) {
				console.log("Error: "  + er);
			} else {
				console.log(data);
			}
		});
	}
})

Results in the following output:



				

View code on GitHub →