Plugin Idea: URL Shortener


#1

I work at a very large organization, and due to bureaucracy and legal departments, I often cannot use a lot of SaaS providers. In my current situation, my company cannot come to an agreement with any services like bit.ly, so I have to roll my own URL shortener.

At it’s core a URL shortener is pretty simple. Just look up a URL and issue a 301. This seems like it could be a pretty good use case for a Kong plugin, so I want to start a discussion to discuss and potential obstacles or features that would be useful. If it seems plausible, I’d love to write it.

A version 0.1 I’m envisioning would be a plugin that exposes an Admin API route such as :8001/shortens (or something with a better name). You would POST to that endpoint with a body containing the full URL, and you would receive an id for the shortened link. Then when hitting a route on the proxy like :8000/shortened/:id (or whatever route for which you configure this plugin), Kong would look at the :id in the url params, look up the full link in the database/cache, then issue a redirect to the URL.

These features so far would be pretty easy to implement, but once you start adding more data like tracking how many times the link has been viewed, and from what location, user agent, etc etc, that starts to make me think this won’t be a good fit because that will add a lot of database writes and Kong is typically not a write heavy application.

I’d like to know if other members of the community would find this plugin useful and if any members of the team foresee any performance detriments to something like this.

Please let me know!