nkoehring / k0r

An URL shortener for individuals, but optimized for speed. This is a mirror of https://git.sr.ht/~koehr/k0r

Home Page:https://k0r.eu

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

k0r.eu

builds.sr.ht status MIT license

A very performant URL shortener service for individuals and small groups.

The service builds upon the Actix web framework and Rusqlite for data handling. Thanks to Actix and the speed optimized SQLite database you can expect 100k requests handled per second on consumer hardware (my laptop).

Quick Start

The database will be automatically initialized with a super user if it is not yet existing. The api key can be found in the programs output, which should look similar to the following example:

$ k0r
Database file k0r.db not found. Create it? [y/N]
y
Added first user with api key 859b397c-a933-461d-a9b1-86dd20084c02
Server is listening on 127.0.0.1:8080

This will create a database file in the current directory. You can also give a path instead:

$ k0r /path/to/database.db

For testing, you can fill the database with test URLs using the application API. There is a helper script and already a file with example URLs inside the db folder:

# assuming you're inside the project directory root and the server is running
./db/insert-via-api.sh 859b397c-a933-461d-a9b1-86dd20084c02 db/test.urls

This inserts a bit under two-hundred URLs fetched from 250kb.club a while ago. The file contains simply one URL per line and the script is not doing any checks and will throw at the API whatever it finds.

API Usage

Get an URL is straight forward as expected:

$ curl 127.0.0.1:8080/1
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>redirect — k0r link shortener service</title>
  <meta http-equiv="refresh" content="2; url=https://example.com" />
</head>
<body>You will be redirected to <a href="https://example.com">an example</a>.</body>
</html>

Inserting a URL is simple as well:

$ payload='{
    "url":"https://example.com",
    "title":"an example",
    "description":"totally examplary url",
    "key":"859b397c-a933-461d-a9b1-86dd20084c02"
  }'
$ curl -X POST localhost:8080 -H 'Content-Type: application/json' -d $payoad

Planned features

This software is still pre-alpha state and most of the planned features are not yet implemented. See the todo list for more information about the planned features and current state of implementation.

About

An URL shortener for individuals, but optimized for speed. This is a mirror of https://git.sr.ht/~koehr/k0r

https://k0r.eu

License:MIT License


Languages

Language:Rust 74.5%Language:HTML 16.0%Language:CSS 5.3%Language:Lua 2.2%Language:Shell 1.9%