Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/modprog/shorty

A small url shortener with minimal configuration
https://github.com/modprog/shorty

Last synced: 25 days ago
JSON representation

A small url shortener with minimal configuration

Awesome Lists containing this project

README

        

= Shorty - URL shortener
:source-highlighter: rouge

== Wordlists

The Corpora of the Universität Leipzig, licensed under https://creativecommons.org/licenses/by/4.0/[CC BY], are used for generating the wordlists. (https://web.archive.org/web/20210730003345/https://wortschatz.uni-leipzig.de/en/usage[Terms of Usage]) You can download the files here: https://wortschatz.uni-leipzig.de/en/download/English[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
a| `/`
| Deletes a shortened URL
Note that this is the same URL as the `GET`
|
|

| GET
a| `/`
| Redirects to the matching `target` URL
|
a| `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`:

```sh
podman run -p 8000:8000 ghcr.io/modprog/shorty
```
or
```sh
docker run -p 8000:8000 ghcr.io/modprog/shorty
```

To set all configurable options:

```sh
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:
```sh
curl -X POST http://localhost:8000/w -d https://togglebit.io/posts/terminal-game-jam/
```

Using random characters:

```sh
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.