braid / shorten
A small PSR-7 and PSR-15 compliant headless url shortener.
Installs: 2
Dependents: 0
Suggesters: 0
Security: 0
Stars: 6
Watchers: 3
Forks: 0
Open Issues: 0
Type:project
Requires
- illuminate/database: ^5.5
- mindplay/middleman: 3.0.0.x-dev
- robmorgan/phinx: ^0.9.1
- zendframework/zend-diactoros: ^1.6
Requires (Dev)
- phpunit/phpunit: ^6.4
This package is not auto-updated.
Last update: 2025-02-16 06:26:30 UTC
README
Need 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.
Installation
Download
Shorten is a small micro application. It is easily installed with composer’s create-project
command.
composer create-project braid/shorten your-shortener-name
Configuration
Shorten comes with two example configuration files. To configure your instance, just copy these files:
cp config.example.php config.php cp phinx.example.yml phinx.yml
config.php
Edit your newly created config.php
as appropriate.
Pro Tip: here’s a quick way to generate an api key:
php -r 'echo bin2hex(openssl_random_pseudo_bytes(32)) . "\n";'
phinx.yml
Shorten uses Rob Morgan’s Phinx for database migrations. Phinx has its own configuration, but the values should be the same as your config.php
database
settings.
Database
Once 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:
vendor/bin/phinx migrate
Server
The 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.
Api
Shorten comes with a simple API for creating, listing, and removing shortened urls.
All api requests MUST include an Authorization
header in the format:
Authorization: Bearer api_secret_here
The return format for redirect resources is JSON. Example:
{ "id": 1, "hash": "ce24227c", "redirect_to": "http://www.google.com", "count": 0, "url": "http://bit.ly/ce24227c" }
Note: Yes DELETE /resources/{id}
would be cleaner, but using simple strings allows for faster routing.
Best practices
Shorten 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 if you want.
Sponsor
Shorten is written and maintained by Braid LLC, and offered freely under an MIT license.