YALS is a simple link shortening service that accepts any validly formatted URI and returns a short (10 character case sensitive alphanumeric identifier) link which may then be used in place of the original link for public or private distribution.
Note: This application is likely to be widely portable across any OS or hardware architectures supported by the official Go compiler, but has only been tested on Linux / AMD64.
A container solution such as Docker or Podman compatible with OCI specification v1.0 or greater.
A functional installation of the official reference implementation Go compiler of version 1.19 or greater.
Clone the repository to the directory.
cd
to the project directory.
Run:
docker build . -t yals
docker run -p 127.0.0.1:8086:8086 yals
Run:
go build
./yals
Note: As a URL cannot contain another url unescaped, the API caller is responsible for base64 encoding the URL to be shortened. You may ask yourself, why are we not doing the typical percent-encoding / URI encoding per RFC 3986? Well! golang/go#21955
To shorten the URL https://www.example.com/coolthing?tacos=yes
:
curl "http://127.0.0.1:8086/api/v1/shorten/aHR0cHM6Ly93d3cuZXhhbXBsZS5jb20vY29vbHRoaW5nP3RhY29zPXllcw=="
Response:
HTTP response code: 200
HTTP response body:
{
"url": "http://127.0.0.1:8086/aGVsbG8hCg",
"error": ""
}
To look up the identifier aGVsbG8hCg
:
curl "http://127.0.0.1:8086/api/v1/lookup/aGVsbG8hCg"
Response:
HTTP response code: 200
HTTP response body:
{
"url": "https://www.example.com/",
"error": ""
}
curl "http://127.0.0.1:8086/aGVsbG8hCg"
Response:
HTTP response code: 302
"Moved temporarily"
HTTP Location header: https://www.example.com/
The application defaults to http://127.0.0.1:8086
for the bind address which is reflected in the generated short links.
See DESIGN.md for other thoughts on the design of the service.