URL Shortener

Enter a URL to shorten

Pro Tip: Use strip to remove GET parameters off end of URL

Here's your shortened url!

Note: shortened url is only valid for 24 hours

Overview

This simple application takes a valid URL and creates a shortened version of it to use. This is done by sending the valid URL back to the server and storing it in a sqlite database. The new record in the table also has an endpoint generated so the value can be accessed.

URL API

There is one api endpoint for this application to use: /api/url. A valid POST request to the api will then add a record to the database and return the sudo random endpoint to the client for the shortened version of the URL. A valid GET request to the api with the endpoint value will return the original URL as a redirect.

Keeping URLs for only one day

I REALLY wanted to setup a redis instance to store the url records. With something like redis I could easily configure the records to expire after a definied time period. In the end I decided it wasn't worth it for such a simple api application. Instead I'm using my existing sqlite database for my website. The biggest challenge is that sqlite doesn't run as a separate daemon/process. I instead adjusted the code to remove records older than one day before returning my GET requests. This ensures records don't build up over time.

If you're interested, you can view the code below.