URL Shortner for Elixir/Erlang
A HTTP/REST API Service for shortening given urls.
POST /
- request body is plain text, which is is the original URL (i.e.curl -XPOST "http://localhost:8888/" -d 'https://google.com/'
) - when everything went fine,HTTP 201
will be returned, having the short url as part of the response body - no json, just plain text.GET /:shorturl-hash
- retrieves the original URL based on the given shorturl hash - if there's no URL stored, or if the URL expired, aHTTP 404
will be returned; if the URL exists,HTTP 302
is returned, having the responselocation
header pointing to the original URL.
make build
make -C docker build
make -C docker postgres && make test
make release
- this will create aprod
releasemake release-docker
- this will create adocker
release, which basically means that is using thedocker.exs
config.
make -C docker postgres && make run
make -C docker run
- this will start all services necessary to runshortler
, and then theshortler
.make -C docker influxdb run
- this will make sure that influxdb is started, and then carry on with the rest of startup.
The timeseries DB, if started, can easily be accessed by any HTTP client, something similar to this:
curl "http://localhost:8086/query?pretty=true" --data-urlencode "db=shortler_clicks" --data-urlencode "q=SELECT * FROM \"requests\""
and you'd be able to see results similar to this:
{
"results": [
{
"statement_id": 0,
"series": [
{
"name": "requests",
"columns": [
"time",
"accept",
"host",
"url",
"user-agent"
],
"values": [
[
"2018-10-14T19:23:24.0571226Z",
"*/*",
"localhost:8888",
"http://localhost:8888/ErhTVwSuHUi",
"curl/7.54.0"
],
[
"2018-10-14T19:23:32.7438721Z",
"*/*",
"localhost:8888",
"http://localhost:8888/ErhTVwSuHUi",
"curl/7.54.0"
],
...
This can be further explored using the InfluxDB capabilities as documented here: (Querying data with the HTTP API)[https://docs.influxdata.com/influxdb/v1.6/guides/querying_data/]