mpngin v0.7.2

A simple and fast URL shortener with built in stats.
  • v0.7.2 - June 6, 2020
  • v0.7.1 - June 6, 2020
  • v0.5.5 - September 25, 2019
  • v0.5.4 - July 5, 2019
  • v0.6.0 - June 3, 2019

MPNG.IN Crystal CI

A simple and fast URL shortener with built in stats. Requires Redis and assumes it is local for lowest possible latency.


Copy env.example to .env and set the values. For the SECRET_TOKEN, try

NOTE: If building in release mode for production, ensure KEMAL_ENV is uncommented in .env and set to production.

Then run:

shards install
crystal run src/

For production, make a release build:

# Assumes .env file is correctly filled out, including KEMAL_ENV=production
crystal build --release src/


Creating an short URL and getting the stats require an application key first.

  1. Create an application first:
➜ curl -X "POST" "http://localhost:3000/application" -H "Authorization: bearer <SECRET_TOKEN_HERE>"

# New app key response
  1. Use the app key in place of the SECRET_TOKEN to make shortened URLs, passing in the final redirect to URL as a application/x-form-urlencoded body param named redirect_url:
➜ curl -X "POST" "http://localhost:3000/" \
     -H 'Authorization: bearer d48655ff210c3e9e4ed8f6ad4f1923a3' \
     -H 'Content-Type: application/x-www-form-urlencoded; charset=utf-8' \
     --data-urlencode "redirect_url="
# Your shiny new shortened redirect URL
  1. Get number of requests for this shortened URL:
➜ curl "http://localhost:3000/541450/stats" \
     -H 'Authorization: bearer d48655ff210c3e9e4ed8f6ad4f1923a3' \
     -H 'Accept: text/plain'

# Request count response

Link Report

MPNGIN can generate a link report in JSON, CSV, or HTML format. Use your SECRET_TOKEN to request the report endoint in which ever format you need:

# For JSON:
➜ curl "http://localhost:3000/report.json" \
     -H 'Authorization: bearer d48655ff210c3e9e4ed8f6ad4f1923a3' \

# Response

# For HTML:
➜ curl "http://localhost:3000/report.html" \
     -H 'Authorization: bearer d48655ff210c3e9e4ed8f6ad4f1923a3' \

# Response
<!doctype html>
<html lang="en">

# For CSV:
➜ curl "http://localhost:3000/report.csv" \
     -H 'Authorization: bearer d48655ff210c3e9e4ed8f6ad4f1923a3' \

# Response
"Short Link","Expanded Link","Request Count"

HTML Report Customization

MPNGIN uses ECR to generate a plain table styled by Bootstrap. You can customize the layout (src/views/layouts/layout.ecr) or the table itself (src/views/report.ecr).

CSV Filename Customization

You can change the file name provided for the downloaded CSV by setting LINK_REPORT_CSV_NAME ENV variable (without extension). See the env.sample file.


For spec tests:

KEMAL_ENV=test crystal spec

For coverage:

KEMAL_ENV=test ./bin/crystal-coverage spec/
open coverage/index.html

NOTE: crystal-coverage generates false positives and is not recommended currently.

Static Analysis

To run static analysis checks, use locally installed Ameba (comes with shards install):



  1. Fork it ( )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request


github statistic
  • 29
  • 0
  • 2
  • 0
  • 4 months ago
  • May 26, 2018

MIT License

Synced at

Tue, 20 Oct 2020 15:13:37 GMT