{"id":15713774,"url":"https://github.com/thewalkingtoast/mpngin","last_synced_at":"2025-07-30T20:03:56.661Z","repository":{"id":54523726,"uuid":"134997896","full_name":"thewalkingtoast/mpngin","owner":"thewalkingtoast","description":"A simple and fast URL shortener with built in stats.","archived":false,"fork":false,"pushed_at":"2023-10-10T18:34:27.000Z","size":104,"stargazers_count":34,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-07T22:33:49.884Z","etag":null,"topics":["crystal","crystal-language","redis","url-shortener"],"latest_commit_sha":null,"homepage":null,"language":"Crystal","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thewalkingtoast.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-05-26T22:10:07.000Z","updated_at":"2025-04-18T19:22:50.000Z","dependencies_parsed_at":"2024-05-02T20:58:02.257Z","dependency_job_id":"f1340d5d-e9b3-4f24-a82e-d5915c1ce901","html_url":"https://github.com/thewalkingtoast/mpngin","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"purl":"pkg:github/thewalkingtoast/mpngin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thewalkingtoast%2Fmpngin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thewalkingtoast%2Fmpngin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thewalkingtoast%2Fmpngin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thewalkingtoast%2Fmpngin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thewalkingtoast","download_url":"https://codeload.github.com/thewalkingtoast/mpngin/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thewalkingtoast%2Fmpngin/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267930586,"owners_count":24167472,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-30T02:00:09.044Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["crystal","crystal-language","redis","url-shortener"],"created_at":"2024-10-03T21:33:25.390Z","updated_at":"2025-07-30T20:03:56.601Z","avatar_url":"https://github.com/thewalkingtoast.png","language":"Crystal","funding_links":[],"categories":["Official Documentation Translations"],"sub_categories":[],"readme":"# MPNG.IN ![Crystal CI](https://github.com/thewalkingtoast/mpngin/workflows/Crystal%20CI/badge.svg)\n\nA simple and fast URL shortener with built in stats. Requires Redis and assumes it is local for lowest possible latency.\n\n## Installation\n\nCopy `env.example` to `.env` and set the values. For the\n`SECRET_TOKEN` you can generate one with `$ crystal eval \"puts Random::Secure.hex(32)\"`.\n\nNOTE: If building in release mode for production, ensure `KEMAL_ENV` is uncommented in `.env` and set to `production`.\n\nThen run:\n```sh\nshards install\ncrystal run src/mpngin.cr\n```\n\n### Production Use\n\nFor production, make a release build with `KEMAL_ENV` uncommented in `.env` and set to `production`:\n\n```sh\n# Assumes .env file is correctly filled out, including KEMAL_ENV=production\nshards build --production --release --static --progress\n```\n\nThe `.env` must accompany the built binary at the same filesystem level. Example production tree:\n\n```\nmpngin\n|_ mpngin (binary)\n|_ .env\n```\n\n## Usage\n\nCreating an short URL and getting the stats require an application key first.\n\n1) Create an application first:\n\n```sh\n➜ curl -X \"POST\" \"http://localhost:7001/application\" -H \"Authorization: bearer \u003cSECRET_TOKEN_HERE\u003e\"\n\n# New app key response\nd48655ff210c3e9e4ed8f6ad4f1923a3\n```\n\n2) Use the app key in place of the `SECRET_TOKEN` to make shortened URLs, passing in the final redirect to URL as a\n`application/x-form-urlencoded` body param named `redirect_url`:\n\n```sh\n➜ curl -X \"POST\" \"http://localhost:7001/\" \\\n     -H 'Authorization: bearer d48655ff210c3e9e4ed8f6ad4f1923a3' \\\n     -H 'Content-Type: application/x-www-form-urlencoded; charset=utf-8' \\\n     --data-urlencode \"redirect_url=https://www.nintendo.com\"\n\n# Your shiny new shortened redirect URL\nhttp://localhost:7001/541450\n```\n\n3) Get number of requests for this shortened URL:\n\n```sh\n➜ curl \"http://localhost:7001/541450/stats\" \\\n     -H 'Authorization: bearer d48655ff210c3e9e4ed8f6ad4f1923a3' \\\n     -H 'Accept: text/plain'\n\n# Request count response\n1337\n```\n\n### Dynamic Short Link Domain at Request Time\n\nYou can change the top-level short link domain at request time via the `short_url` parameter when creating a short link. For example, if normally you use `mpng.in` for the short URL but want to use `thehorde.org` instead on a per-request basis, you can easily do so:\n\n```sh\n➜ curl -X \"POST\" \"http://localhost:7001/\" \\\n     -H 'Authorization: bearer d48655ff210c3e9e4ed8f6ad4f1923a3' \\\n     -H 'Content-Type: application/x-www-form-urlencoded; charset=utf-8' \\\n     --data-urlencode \"redirect_url=https://www.nintendo.com\" \\\n     --data-urlencode \"short_url=https://thehorde.org\"\n\n# Your shiny new shortened redirect URL with custom short domain\nhttps://thehorde.org/f1274e\n```\n\n*Note: Short codes are unique per short URL*\n\n## Link Inspect\n\nTo 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:\n\n```sh\n# For JSON:\n➜ curl \"http://localhost:7001/541450/inspect.json\" \\\n     -H 'Authorization: bearer d48655ff210c3e9e4ed8f6ad4f1923a3' \\\n\n# Response\n{\"short_link\":...}\n\n# For HTML:\n➜ curl \"http://localhost:7001/541450/inspect.html\" \\\n     -H 'Authorization: bearer d48655ff210c3e9e4ed8f6ad4f1923a3' \\\n\n# Response\n\u003c!doctype html\u003e\n\u003chtml lang=\"en\"\u003e\n...\n\n# For CSV:\n➜ curl \"http://localhost:7001/541450/inspect.csv\" \\\n     -H 'Authorization: bearer d48655ff210c3e9e4ed8f6ad4f1923a3' \\\n\n# Response\n\"Short Link\",\"Expanded Link\",\"Request Count\",\"Report Date\"\n\"...\"\n```\n\n## Link Report\n\nMPNGIN 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:\n\n```sh\n# For JSON:\n➜ curl \"http://localhost:7001/report.json\" \\\n     -H 'Authorization: bearer d48655ff210c3e9e4ed8f6ad4f1923a3' \\\n\n# Response\n[{\"short_link\":...}]\n\n# For HTML:\n➜ curl \"http://localhost:7001/report.html\" \\\n     -H 'Authorization: bearer d48655ff210c3e9e4ed8f6ad4f1923a3' \\\n\n# Response\n\u003c!doctype html\u003e\n\u003chtml lang=\"en\"\u003e\n...\n\n# For CSV:\n➜ curl \"http://localhost:7001/report.csv\" \\\n     -H 'Authorization: bearer d48655ff210c3e9e4ed8f6ad4f1923a3' \\\n\n# Response\n\"Short Link\",\"Expanded Link\",\"Request Count\"\n\"...\"\n```\n\n#### HTML Report Customization\n\nMPNGIN uses ECR to generate a plain table styled by [Bootstrap](https://getbootstrap.com). You can customize the layout (`src/views/layouts/layout.ecr`) or the table itself (`src/views/report.ecr`).\n\n#### CSV Filename Customization\n\nYou 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.\n\n*Note: All downstream applications get the same report. That is, short links are not scoped to downstream applications.*\n\n## Testing\n\nFor spec tests:\n```sh\nKEMAL_ENV=test crystal spec\n```\n\n## Static Analysis\n\nTo run static analysis checks, use locally installed [Ameba](https://github.com/veelenga/ameba) (comes with `shards install`):\n```\n./bin/ameba\n```\n\n## Contributing\n\n1. Fork it ( https://github.com/thewalkingtoast/mpngin/fork )\n2. Create your feature branch (git checkout -b my-new-feature)\n3. Commit your changes (git commit -am 'Add some feature')\n4. Push to the branch (git push origin my-new-feature)\n5. Create a new Pull Request\n\n## Contributors\n\n- [thewalkingtoast](https://github.com/thewalkingtoast) Adam Radabaugh - creator, maintainer\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthewalkingtoast%2Fmpngin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthewalkingtoast%2Fmpngin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthewalkingtoast%2Fmpngin/lists"}