{"id":28391407,"url":"https://github.com/wearebraid/shorten","last_synced_at":"2025-06-25T21:31:26.317Z","repository":{"id":62496546,"uuid":"108067833","full_name":"wearebraid/shorten","owner":"wearebraid","description":"Simple PSR-7 and PSR-15 compliant headless URL shortener.","archived":false,"fork":false,"pushed_at":"2017-10-24T15:32:29.000Z","size":335,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-31T19:34:08.662Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","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/wearebraid.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-24T02:38:16.000Z","updated_at":"2021-01-18T14:51:43.000Z","dependencies_parsed_at":"2022-11-02T09:46:00.120Z","dependency_job_id":null,"html_url":"https://github.com/wearebraid/shorten","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/wearebraid/shorten","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wearebraid%2Fshorten","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wearebraid%2Fshorten/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wearebraid%2Fshorten/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wearebraid%2Fshorten/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wearebraid","download_url":"https://codeload.github.com/wearebraid/shorten/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wearebraid%2Fshorten/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261956004,"owners_count":23235994,"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","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":[],"created_at":"2025-05-31T09:12:03.415Z","updated_at":"2025-06-25T21:31:26.309Z","avatar_url":"https://github.com/wearebraid.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Shorten\n---------\n[![Build Status](https://scrutinizer-ci.com/g/wearebraid/shorten/badges/build.png?b=master)](https://scrutinizer-ci.com/g/wearebraid/shorten/build-status/master)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/wearebraid/shorten/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/wearebraid/shorten/?branch=master)\n[![Code Coverage](https://scrutinizer-ci.com/g/wearebraid/shorten/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/wearebraid/shorten/?branch=master)\n[![License](https://poser.pugx.org/braid/shorten/license)](https://packagist.org/packages/braid/shorten)\n\n\nNeed an easy to use custom URL shortener like bit.ly, t.co, goo.gl? Shorten is a simple, PSR-7 and PSR-15 compliant headless URL shortener made for developers like you.\n\n## Installation\n\n### Download\n\nShorten is a small micro application. It is easily installed with composer’s `create-project` command.\n\n```sh\ncomposer create-project braid/shorten your-shortener-name\n```\n\n### Configuration\n\nShorten comes with two example configuration files. To configure your instance, just copy these files:\n\n```sh\ncp config.example.php config.php\ncp phinx.example.yml phinx.yml\n```\n\n#### config.php\n\nEdit your newly created `config.php` as appropriate.\n\nOption        | Description\n--------------|--------------------------------------\n`base_url`    | You'll want to set your application’s `base_url` to the domain name you are using as a shortener (http://bit.ly for example).\n`api_secret`  | Choose a randomly generated key (\u003e32 bytes recommended). This will be your application’s `Bearer` token for api requests.\n`database`    | Shorten uses Laravel’s excellent [Eloquent ORM](https://laravel.com/docs/5.5/eloquent). Configure the database credentials here. MySQL/MariaDB is recommended for medium/high traffic, but a simple SQLite is also supported.\n\nPro Tip: here’s a quick way to generate an api key:\n\n```sh\nphp -r 'echo bin2hex(openssl_random_pseudo_bytes(32)) . \"\\n\";'\n```\n\n#### phinx.yml\n\nShorten uses Rob Morgan’s [Phinx](https://phinx.org/) for database migrations. Phinx has its own configuration, but the values should be the same as your `config.php` `database` settings.\n\n### Database\n\nOnce your configuration files have been created and updated, go ahead and create the database you specified in the above configuration file. Then simply run the migrations:\n\n```sh\nvendor/bin/phinx migrate\n```\n\n### Server\n\nThe last step is to simply point an http server or virtual host to the `public` directory. This documentation won't go into detail on how to setup Apache or nginx.\n\n## Api\n\nShorten comes with a simple API for creating, listing, and removing shortened urls.\n\nMethod   | Endpoint      | Description\n---------|---------------|-------------------------------------\n`GET`    | `/resources`  | List all shortened URLs currently stored.\n`POST`   | `/resources`  | Creates a new URL. Must include a JSON body with a `url` attribute.\n`DELETE` | `/resources`  | Removes a shortened URL. Must include a JSON body with an `id` attribute.\n\nAll api requests MUST include an `Authorization` header in the format:\n\n```\nAuthorization: Bearer api_secret_here\n```\n\nThe return format for redirect resources is JSON. Example:\n\n```json\n{\n  \"id\": 1,\n  \"hash\": \"ce24227c\",\n  \"redirect_to\": \"http://www.google.com\",\n  \"count\": 0,\n  \"url\": \"http://bit.ly/ce24227c\"\n}\n```\n\n_Note: Yes `DELETE /resources/{id}` would be cleaner, but using simple strings allows for faster routing._\n\n## Best practices\n\nShorten is intended to be a simple set-and-forget service you can use internally at your organization or embed into the apps you build. Keep in mind it is a project and not a dependency, so you are free and encouraged to bolt on additional [PSR-15 middleware](https://github.com/middlewares/psr15-middlewares) if you want.\n\n## Sponsor\n\nShorten is written and maintained by [Braid LLC](https://www.wearebraid.com), and offered freely under an MIT license.\n\n[\u003cimg src=\"https://assets.wearebraid.com/sig.png\" title=\"Written and maintained by Braid LLC\" alt=\"Braid LLC\" width=\"150\" height=\"44\"\u003e](https://www.wearebraid.com)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwearebraid%2Fshorten","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwearebraid%2Fshorten","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwearebraid%2Fshorten/lists"}