Testing Webhooks from your Command Line with Node.js
Webhooks are a mechanism of defining your own HTTP callbacks for remote web services that are pushed data whenever an event occurs. Most importantly, it’s another tool for leveraging web services alongside an HTTP client.
The difficulty of webhooks is that you are no longer the client, and things which are easy to test locally (like accessing a REST API) suddenly become difficult from your command line. Since Webhooks must be public URLs, http://localhost:5000/ won’t cut it. Just experimenting with webhooks is nontrivial.
Very recently, the excellent and free Localtunnel v2 was released, allowing you to expose your local server at a public localtunnel.com subdomain of your choice, as long as it’s available. Smee (on Github) is a Node.js module that calls Localtunnel to create a persistent webhook that calls a local callback. A unique domain of the form smee045465383834645896.v2.localtunnel.com is generated and saved for your script, letting you maintain the same URL even after restarting.
Smee works entirely from code. Just define a new hook and listen for callbacks:
var smee = require('smee');
smee.persistentHook(function (err, hook) {
console.log('Your webhook URL:', hook.url);
hook.on('callback', function (payload) { /* webhook payload */ });
});
The following example uses the very minimal Venmo API, which exposes nothing but an ability to set up a webhook to trigger each time a payment is made or received. To install Smee, first install Localtunnel via easy_install localtunnel or pip install localtunnel. Next, npm install smee and run this script:
After a moment you should see something like the following in your console:
Your webhook URL: http://smee3484480480040896.v2.localtunnel.com ...
Copy that URL and go to your Venmo Developers Settings. Click the “Receipts API” option and set your callback URL:

Click “Save Changes”. Next, click on “Your Applications” above “Receipts API”. You’ll see an entry called “Venmo Receipts API”. Copy the “Secret” key and paste it into your script, then stop and restart your script to load your secret key. (Note how the URL remains the same after the script is restarted.)
Make any test payment on Venmo and the receipt payload will appear in your console:
$ node venmo.js
Your webhook URL: http://smee3484480480040896.v2.localtunnel.com ...
[ { via: 'Venmo.com',
publish_to_venmo: 1,
pay_or_charge: 'pay',
from_user:
{ username: 'timcameronryan',
twitter_username: 'timcameronryan',
facebook_id: null},
from_user_id: 56740,
to_user_id: 0,
to_user:
{ username: ... } ]
Simple! Once you’re comfortable with how your code is handling a webhook push, it’s easy to move your logic to a permanent URL.
Localtunnel by Jeff Lindsay is free, though donations are accepted. If you’re interested in a permanent localhost tunneling solution, check out Pagekite that provides permanent URLs like http://tcr.pagekite.me and unlimited subdomains.
I’m enrolled in a class at Olin this semester called Real Products, Real Markets. Our first team project is to conceptualize, design, produce, and sell items cut from sheet metal, in just four weeks.
This is one of our scrapped prototype ideas: Social Media Charm Bracelets. Luckily these made it on to our test cut sheet, since how else would I be able to publicly declare my sweet Pinterest cred.
Controlling your mouse using an iPad and HTML5
A friend recently showed me the JazzMutant Lemur, a swank multitouch audio controller for synthesizers, and asked how he might duplicate its functionality with an iPad. Though it would definitely be possible in Objective-C, I told him the quickest way to get started would be to make an HTML5 app. To demonstrate, I made a full-screen mouse controller on the iPad, which connects to a Python server on a computer using WebSockets.
What you’ll need for iMousePad:
- A Linux installation
- An iPad (iOS 4.2+)
- Both to be connected to the same network.
Mug: JavaScript Compiler for the JVM
A few months ago I wrote about compiling CoffeeScript into Java. Since then I’ve wanted to use JavaScript on a few target platforms running Java, so I’ve developed a complete JavaScript compiler for the JVM.
Rhino is the de-facto JavaScript interpreter for Java, but Mug has different priorities. There is no interpretation involved; all code is statically compiled before running. This has led to code running 2x as fast in some cases, compared to Rhino’s compiled mode. Mug’s standard library is comparatively small, just ~150k for its object classes and the default library. The biggest architectural difference is that Mug is modeled around CommonJS modules. Each compiled JavaScript file is an independent module and can be loaded using require. Java interacts with JavaScript via its exports object, and you can easily write modules entirely in Java to extend Mug’s capabilities.
Mug implements much of the ECMAScript 3 spec right now, though it is still a work in progress. To get started, check out Mug on GitHub and the README. Let me know of any issues you find.
And to show you what Mug is capable of, here’s my related project, Mug running on Android.
Like an easter egg, but for your internet
I love when I’m browsing high-profile websites, and I realize they’re using the Silk icon set. It’s like a hidden game.
For additional points, find software that uses it.
Mug, a Java Compiler
CoffeeScript is my favorite new language at the moment. It’s a syntatically light preprocessor to JavaScript, influenced by Python and Ruby, that exposes the niceties of JS’s loose typing and lambdas without gaudy Perhaps what I enjoy most about CoffeeScript is that it isn’t an entire language, just a syntax. Because of that, we can rather easily repurpose jashkenas’ work from compiling to JavaScript to any language—in this case, Java. You can interactively play with a demo of Mug, a CoffeeScript-to-Java Compiler. It can take a subset of CoffeeScript code and compile it to valid (albeit gaudy) Java source. The resulting code, however verbose, is 1:1 with its input, accompanied by some generated class structs and scope objects. Objects in JavaScript become glorified The results of such a hacky conversion are actually surprisingly fast on HotSpot. For the “Binary Trees” benchmark, the Mug compiled version runs about ~3–4x slower than V8 on my machine, but ~7x faster than Rhino, while still maintaining many of the benefits of a dynamic language (closures, prototypical inheritance, hashes, etc.) The question becomes you value the tradeoff of flexibility and speed. As a CoffeeScript compiler, Mug is obviously lacking the features of a complete JavaScript implementation. But just as CoffeeScript was meant to improve the experience of programming on the web, Mug could conceivably develop its own semantics and be a light preprocessor for Java. While there are many alternativesto programming the JVM, I expect that a class of “little languages” like CoffeeScript that compile into more familiar languages will start cropping up. Rather than reinvent the programming experience, these simply make the existing programming experience programmers are forced into easier for day-to-day use.vars and (function () { ... })s littering your code. Once you start using its comprehensions and loop structures, it feels silly to go back to scripting Java-inspired syntax on the web.HashMaps, and type conversions are large switch structures.
Passion Pit Pursuits
Olin has these nifty things called “Passionate Pursuits” where you get to take an (essentially) one-credit course per semester on a topic of your choosing. For example: …you get the idea. You write up a proposal and get it approved though the Passionate Pursuits Board. You can even get funding, up to about $200, for lessons or equipment. It’s pretty ballin’. Naturally Olin classes are workload enough and I’ve put it off first semester. But half-semester classes having just ended, I decided that starting a Passionate Pursuit midway through a semester (despite doubling the number of hours per week I’d need to work at it) would be better than nothing. I decided, ultimately, a good use of my time would be guitar lessons, since it’s been on my To-Do list for years. Of course, the very week applications are due, I discover there’s no funding left. I’m left in the same boat as every other-last minute applicant. Whoops. …until I realize, wait, I already have a guitar. …and I already have lessons. It’s the Internet. So paperwork be damned, I’m going to learn how to play guitar by summer. Just like Facebook, it needn’t be written down to still be official. (gg.) Don’t you hate it when the only thing holding you back is thinking you need a reason?
LOAD “*”,8,1
Any professional web presence demands your wordly thoughts be serialized in words! But what I really want, is to serialize my wordy thoughts into worlds.
Github (@tcr)
Twitter (@timcameronryan)
LinkedIn
Email (tim@timryan.org)