All Projects → thewalkingtoast → mpngin

thewalkingtoast / mpngin

Licence: MIT license
A simple and fast URL shortener with built in stats.

Programming Languages

crystal
512 projects
HTML
75241 projects
Dockerfile
14818 projects

Projects that are alternatives of or similar to mpngin

url-shortener
A URL Shortener Application built with Node.js, Express and MongoDB
Stars: ✭ 16 (-48.39%)
Mutual labels:  url-shortener
1y
A template project to build a short URL manager with Eleventy
Stars: ✭ 68 (+119.35%)
Mutual labels:  url-shortener
Leafgem
🌿💎 The humble beginnings of a 2D game engine in Crystal! [in-progress]
Stars: ✭ 72 (+132.26%)
Mutual labels:  crystal-language
tiny0
Custom URL shortener in Flask.
Stars: ✭ 60 (+93.55%)
Mutual labels:  url-shortener
FireShort
A URL Shortener made using React.JS and Google Firestore
Stars: ✭ 29 (-6.45%)
Mutual labels:  url-shortener
dwarf
A O(1) URL shortener microservice backed by redis and gRPC communication.
Stars: ✭ 33 (+6.45%)
Mutual labels:  url-shortener
secusu
SЁCU is a public API to store self-destructing data payloads with url shortener and handle anonymous chat-rooms.
Stars: ✭ 24 (-22.58%)
Mutual labels:  url-shortener
zone
A URL shortener / note sharing service.
Stars: ✭ 18 (-41.94%)
Mutual labels:  url-shortener
secp256k1.cr
a native library implementing secp256k1 purely for the crystal language.
Stars: ✭ 34 (+9.68%)
Mutual labels:  crystal-language
yaus
Deprecated URL shortener
Stars: ✭ 26 (-16.13%)
Mutual labels:  url-shortener
miniurl
A production-ready URL shortener microservice.
Stars: ✭ 20 (-35.48%)
Mutual labels:  url-shortener
yii2-minify-url
Project on YII2 framework for create short url (url shortener)
Stars: ✭ 15 (-51.61%)
Mutual labels:  url-shortener
orion
A Crystal router
Stars: ✭ 115 (+270.97%)
Mutual labels:  crystal-language
Becoditive-API
The official API of beCoditive with many endpoints like memes, animals, image manipulation, url shortner, etc.
Stars: ✭ 14 (-54.84%)
Mutual labels:  url-shortener
mongo orm
Mongo ORM: A simple ORM for using MongoDB with the crystal programming language, designed for use with Amber. Based loosely on Granite ORM. Supports Rails-esque models, associations and embedded documents.
Stars: ✭ 32 (+3.23%)
Mutual labels:  crystal-language
em-shorty
Another URL shortener based on Event Machine and rack-fiber_pool
Stars: ✭ 56 (+80.65%)
Mutual labels:  url-shortener
delta
A modern file uploader + URL shortner written in node for your private cloud. low memory overhead + secure
Stars: ✭ 103 (+232.26%)
Mutual labels:  url-shortener
await async
Provide await and async methods to Crystal Lang
Stars: ✭ 71 (+129.03%)
Mutual labels:  crystal-language
throw-me
A url shortener made with nextjs and postgresql database operated with Prisma
Stars: ✭ 34 (+9.68%)
Mutual labels:  url-shortener
laravel-url-shortener
URL shortener for Laravel
Stars: ✭ 26 (-16.13%)
Mutual labels:  url-shortener

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.

Installation

Copy env.example to .env and set the values. For the SECRET_TOKEN, try Random.new.hex(32).

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/mpngin.cr

Production Use

For production, make a release build with KEMAL_ENV uncommented in .env and set to production:

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

The .env must accompany the built binary at the same filesystem level. Example production tree:

mpngin
|_ mpgin (binary)
|_ .env

Usage

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

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

# New app key response
d48655ff210c3e9e4ed8f6ad4f1923a3
  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:7001/" \
     -H 'Authorization: bearer d48655ff210c3e9e4ed8f6ad4f1923a3' \
     -H 'Content-Type: application/x-www-form-urlencoded; charset=utf-8' \
     --data-urlencode "redirect_url=https://www.nintendo.com"
     
# Your shiny new shortened redirect URL
http://localhost:7001/541450
  1. Get number of requests for this shortened URL:
➜ curl "http://localhost:7001/541450/stats" \
     -H 'Authorization: bearer d48655ff210c3e9e4ed8f6ad4f1923a3' \
     -H 'Accept: text/plain'

# Request count response
1337

Link Inspect

To get more detailed information, you can also inspect a link to get info such as the expanded link and request count with a report timestamp in which ever format you need:

# For JSON:
➜ curl "http://localhost:7001/541450/inspect.json" \
     -H 'Authorization: bearer d48655ff210c3e9e4ed8f6ad4f1923a3' \

# Response
{"short_link":...}

# For HTML:
➜ curl "http://localhost:7001/541450/inspect.html" \
     -H 'Authorization: bearer d48655ff210c3e9e4ed8f6ad4f1923a3' \

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

# For CSV:
➜ curl "http://localhost:7001/541450/inspect.csv" \
     -H 'Authorization: bearer d48655ff210c3e9e4ed8f6ad4f1923a3' \

# Response
"Short Link","Expanded Link","Request Count","Report Date"
"..."

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:7001/report.json" \
     -H 'Authorization: bearer d48655ff210c3e9e4ed8f6ad4f1923a3' \

# Response
[{"short_link":...}]

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

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

# For CSV:
➜ curl "http://localhost:7001/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.

Testing

For spec tests:

KEMAL_ENV=test crystal spec

Static Analysis

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

./bin/ameba

Contributing

  1. Fork it ( https://github.com/thewalkingtoast/mpngin/fork )
  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

Contributors

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].