Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aliou/short.ex
A URL shortener toolkit written in Elixir. [hobby project]
https://github.com/aliou/short.ex
Last synced: 1 day ago
JSON representation
A URL shortener toolkit written in Elixir. [hobby project]
- Host: GitHub
- URL: https://github.com/aliou/short.ex
- Owner: aliou
- License: mit
- Created: 2017-07-12T19:02:14.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-12-17T20:16:59.000Z (almost 7 years ago)
- Last Synced: 2024-09-19T02:53:59.926Z (about 2 months ago)
- Language: Elixir
- Homepage:
- Size: 131 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Short
A WIP URL shortener toolkit written in Elixir, inspired by [Guillotine][guillotine].
## Usage
The easiest way to get started is to use the built-in Plug Router and memory adapter.
First create a supervised application :
```shell
$ mix new my_app --sup
```Add Short to your dependencies and applications, along with the Cowboy
web server:```elixir
# mix.exsdef application do
[applications: [:short, :cowboy]]
enddefp deps do
[
...
{:short, "~> 0.0.3"},
{:cowboy, "~> 1.0.0"},
...
]
end
```Configure Short to use the In Memory Adapter:
```elixir
# config/config.exsconfig :short, :adapter, Short.Adapters.InMemory
```Finally, add the router to your application's supervisor tree:
```elixir
# lib/my_app.exdefmodule MyApp do
use Application# See https://hexdocs.pm/elixir/Application.html
# for more information on OTP Applications
def start(_type, _args) do
import Supervisor.Specchildren = [
# 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:
```shell
$ curl http://localhost:4001 -i \
> -F "url=https://aliou.me"
```You can also specify your own code too:
```shell
$ curl http://localhost:4001 -i \
> -F "url=https://aliou.me" \
> -F "code=abc"
```[guillotine]: https://github.com/technoweenie/guillotine