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 as a key/value pair in our valkey database. We store this using two different keys, one with the endpoint (short code), and another with the full url. This allows our code to lookup both ways so we can see if we have a key already for a url, and if so we reuse it.

Use the dropdowns below to learn even more!

URL API

There is one api endpoint for this application to use: /api/url. A valid POST request to the api will then add both keys to the valkey 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.

The api also takes a strip parameter that if true will strip the GET params from the url.

Keeping URLs for only one day

I used valkey (redis fork) as my database because I can easily set an expiration on each key for 1 day. I previously had a sqlite table and would create a record with a created_date that I would then use to cleanup the records older than a day.

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