PHP Classes

PHP URL Shortener API: Provides an API to create and expand short URLs

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 162 All time: 8,944 This week: 524Up
Version License PHP version Categories
ushort 1.0The PHP License7HTTP, PHP 5, Web services
Description 

Author

This package provides an API to create and expand short URLs.

It can redirect a request based on the short URL.

It provides an API application with functions that can create short URL versions of a given URL and expand previously shortened URLs.

Innovation Award
PHP Programming Innovation award nominee
October 2021
Number 3


Prize: 1 Year Subscription to NomadPHP Advanced PHP Learning
Short URLs are helpful to allow users that want to share URLs that are simpler to type than the original URLs.

This package provides a URL shortening and expanding service that is made available as an API.

This way, any developer can use the URL shortener services without managing the service that impĺements the actions that the service provides.

Manuel Lemos
Picture of Julio Vergara
  Performance   Level  
Innovation award
Innovation award
Nominee: 2x

 

Documentation

URL Shortener

Requirements:

  • PHP 7.4 or above
  • composer
  • node / npm

Installation

clone the project from the Github repository, enter the project folder, open a terminal inside the project folder and run:

  composer install
  npm install
  npm run dev

You need to create your .env file; inside the project folder run the following command:

  cp .env.example .env

then setup your db schema and db credentials into the .env file and create the database using your favorite method (phpMyAdmin, MySQL Workbench, etc).

NOTE: It is very important to put inside your .env file, in the APP_URL key, the url that you are using to execute this project. For example, if you use the web server that comes with Laravel, when running 'php artisan serve', that url will usually be 'http://127.0.0.1:8000'; however, if you use a web server like Xampp or Laragon and create a virtual host, you must put the url of the virtual host that you created.

After that you need to create the database tables and populate them with data by running:

  php artisan migrate --seed

After that, a default user is created with the following credentials:

  User:  admin
  Email: admin@admin.com
  Pswrd: password

API End-Points

http://{your-url}/api/v1/url/shortener

This will generate a short url that points to the provided real url, you need to send a GET request with a json body as follows:

  {
    "url" : "your-real-url-here"
  }

if succeed, the request will respond with a json body as follows:

  {
    "short_url" : "generated-short-url-here"
  }

http://{your-url}/api/v1/url/top

This will generate a Json array with the top 100 most visited Urls, you need to send a GET request without a body

http://{your-url}/api/v1/url/real

This will respond with the real Url that the provided short url points to, you need to send a GET request with a json body as follows:

  {
    "url" : "your-short-url-here"
  }

if succeed, the request will respond with a json body as follows:

  {
    "real_url" : "your-real-url-here"
  }

Acknowledgements

In this project I show how to work with:

- Creating an API - Fetching an API - Livewire components - Livewire modals

Improvements

- To have separate and related tables since the same real URL could have several short URLs associated with it. This would also help in scalability of the application and in integration with other systems. - Create a token-based authentication for the API; this way, requests to the API could be limited in a free subscription model and have another paid subscription model with unlimited requests. - Create a pagination for the Top 100 URLs view.


  Files folder image Files (163)  
File Role Description
Files folder imageapp (7 directories)
Files folder imagebootstrap (1 file)
Files folder imageconfig (17 files)
Files folder imagedatabase (3 directories)
Files folder imagepublic (5 files, 2 directories)
Files folder imageresources (5 directories)
Files folder imageroutes (4 files)
Files folder imagetests (2 files, 2 directories)
Accessible without login Plain text file .editorconfig Data Auxiliary data
Accessible without login Plain text file .env.example Data Auxiliary data
Accessible without login Plain text file .styleci.yml Data Auxiliary data
Plain text file artisan Class Class source
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file package-lock.json Data Auxiliary data
Accessible without login Plain text file package.json Data Auxiliary data
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file server.php Aux. Auxiliary script
Accessible without login Plain text file tailwind.config.js Data Auxiliary data
Accessible without login Plain text file webpack.mix.js Data Auxiliary data

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:162
This week:0
All time:8,944
This week:524Up