HTTP Toolbox

As Web Developers, we need to know how to work with HTTP from every angle. I gave a 2-hour tutorial at PHP UK that included some of my most trusted tools – but it was sold out and a bunch of people asked me if there was video (there wasn’t, tutorials make little sense when videoed). Instead, I thought I’d try to set out a self-study version of the workshop (I rarely teach these days so I’m unlikely to deliver it anywhere else).

There’s a slide deck, some exercises and a sample repo on GitHub … let’s dive in! Continue reading

Using Config Files with Ngrok

I’m a huge fan of Ngrok, a tool to create a secure tunnel to your laptop. It is brilliant for testing, well, anything running locally really. Someone asked me about my setup recently and I’m using a couple of config files to keep things quick and consistent, so I thought I’d share here what I shared with them.

You can use a central config file for ngrok, and/or specific config files for each project. I use both, so I’ll show you around my setup. Continue reading

Copying CouchDB Data Between Laptops

I’m a regular and happy user of Apache CouchDB, so much so in fact that I’m writing a library to talk to it from PHP. While working on tweaking a feature, I realised that the laptop I use for development didn’t have the right/enough data on it to test this particular thing – but that I had a suitable database on my other laptop. Copying data between CouchDB installations is very easy because it has an HTTP API, but usually when I do this at least one endpoint is web-accessible. Enter one of my favourite tools: ngrok.

Ngrok allows me to make the CouchDB on one machine visible to the world (with all the security caveats that this entails! It’s a random URL, never leave the tunnel open longer than you need it, etc) with a command like this:

ngrok http 5984

This opens a tunnel to my local machine on port 5984 which is CouchDB’s default port. I’m running a local dev instance that doesn’t need a username or password which makes this simpler if not exactly secure. I get a gobbledeegook ngrok URL that will allow anyone, anywhere to talk to my CouchDB.

Then I went ahead and on the other laptop, used the web interface to start replication from the sample products database on the local machine over to the one on the ngrok URL.

As soon as it starts, the first laptop shows that there’s traffic coming over the ngrok link – and a few minutes later I had the database I wanted and can go ahead and work on this feature.

Use Ngrok Dashboard from VM

I’m a huge fan of ngrok, a tool that allows you to open a secure tunnel from your machine to the outside world to enable testing APIs and things. Mostly I use virtual machines for development, but by default the ngrok dashboard is only available when requested from the machine that ngrok is running on … and I want to be able to see the web interface from my host machine.

This is a config setting but it can’t be supplied on the command line, instead create a file called ~/.ngrok2/ngrok.yml and add the following line:

web_addr: 0.0.0.0:4040

This will enable you to then reach the web interface at [VM IP or hostname]:4040.

Use Ngrok for Testing APIs on Dev

Recently I was hastily building an API for a client and I wanted to run some tests against it. I’ve written before about using Runscope for API testing, but this was against a local dev platform (inside a VM, not directly on my laptop) rather than a public API. The same problem arises if you want to access a local site or API from elsewhere or from a mobile device. In all these scenarios, ngrok is your friend. Continue reading