ghurl URL Shortener

A URL Shortener with no back-end server

04 Jun 2014

by Guilherme Berger

I wanted to explore ways I could (ab)use the GitHub pages and repositores ecosystem by creating working systems that would otherwise need a back-end server.

I was inspired by GitHub Resumé, which uses an opt-in system based on starring the repository. Other sources of inspiration were repositories that use pull requests to maintain information about, e.g., a tech meetup group in a certain city.

I created ghurl, a URL shortener. My idea was to use GitHub issues, combined with the GitHub API, to store and retrieve the long URLs.

Here’s a URL pointing to this post, and here’s the GitHub issue it refers to.

The user’s flow goes like this:

  1. Create an issue on the ghurl/db repository. The title of the issue should be the URL you want to redirect to.

  2. Note n, the issue’s number.

  3. Construct your shortened URL using n: https://ghurl.github.io/?n

Then, when the user accesses the “shortened URL” (it’s not really that short, unless I buy a custom domain), I use the issue’s number (from the query string) to send an AJAX call to the GitHub API. When it’s done, I use the issue’s title as the URL to redirect the user to.

The short URLs contain the issue number in the query string, so I could later retrieve them from the repo. And by using a query string, I effectively have a catch-all URL into a single HTML page: perfect for using GitHub pages for hosting the static HTML+JS+CSS files.

Of course, nobody should really use this service in the real world, for several reasons:

However, I still plan to improve its usability a little bit. Here’s what’s on my mind:

It was fun to bend the environment to support a minimalistic system, and I look forward to tackling a new challenge.


About the author

Guilherme Berger