A WIP URL shortener toolkit written in Elixir, inspired by Guillotine.
The easiest way to get started is to use the built-in Plug Router and memory adapter.
First create a supervised application :
$ mix new my_app --sup
Add Short to your dependencies and applications, along with the Cowboy web server:
# mix.exs
def application do
[applications: [:short, :cowboy]]
end
defp deps do
[
...
{:short, "~> 0.0.3"},
{:cowboy, "~> 1.0.0"},
...
]
end
Configure Short to use the In Memory Adapter:
# config/config.exs
config :short, :adapter, Short.Adapters.InMemory
Finally, add the router to your application's supervisor tree:
# lib/my_app.ex
defmodule MyApp do
use Application
# See https://hexdocs.pm/elixir/Application.html
# for more information on OTP Applications
def start(_type, _args) do
import Supervisor.Spec
children = [
# Define workers and child supervisors to be supervised
Plug.Adapters.Cowboy.child_spec(:http, Short.Router, [], [port: 4001])
]
# See https://hexdocs.pm/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: MyApp.Supervisor]
Supervisor.start_link(children, opts)
end
end
Once you have your application running, you can add URLs with a POST request:
$ curl http://localhost:4001 -i \
> -F "url=https://aliou.me"
You can also specify your own code too:
$ curl http://localhost:4001 -i \
> -F "url=https://aliou.me" \
> -F "code=abc"