/shorty

A small url shortener with minimal configuration

Primary LanguageRustMIT LicenseMIT

Shorty - URL shortener

Wordlists

The Corpora of the Universität Leipzig, licensed under CC BY, are used for generating the wordlists. (Terms of Usage) You can download the files here: Corpora.

API

Method Path Description Body Response

POST

/w

Short a URL via wordlist

The URL to shorten

The shortened URL

POST

/c

Short a URL via random characters [a-zA-Z0-9]

The URL to shorten

The shortened URL

DELETE

/<ident>

Deletes a shortened URL Note that this is the same URL as the GET

GET

/<ident>

Redirects to the matching target URL

307

Configuration

You can configure shorty via environment variables. You can set those via the --env tag:

Name

Default

Description

BASE_URL

http://127.0.0.1:8000/

The URL returned when shortening urls.

CHARED_LENGTH

4

The length of the random characters used for shortened URL’s.

WORDED_LENGTH

1

The length of the random words used for shortened URL’s.

PASSWORD

NOT-SET

If set POST and DELETE requests are only authenticated with the cookie PASSWORD set to the correct password.

Examples

You can run shorty with docker or podman:

podman run -p 8000:8000 ghcr.io/modprog/shorty

or

docker run -p 8000:8000 ghcr.io/modprog/shorty

To set all configurable options:

podman run -p 8000:8000 \
  --env WORDED_LENGTH=1 --env CHARED_LENGTH=4 --env BASE_URL=http://127.0.0.1:8000/ \
  ghcr.io/modprog/shorty

To shorten a URL make a POST request:

Using the wordlist:

curl -X POST http://localhost:8000/w -d https://togglebit.io/posts/terminal-game-jam/

Using random characters:

curl -X POST http://localhost:8000/c -d https://togglebit.io/posts/terminal-game-jam/

Afterwards just open the returned URL in a browser of your choice.