PHP Classes

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

Recommend this page to a friend!
  Info   View files Documentation   View files View files (163)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (1)    
Last Updated Ratings Unique User Downloads Download Rankings
2021-10-26 (24 days ago) RSS 2.0 feedNot yet rated by the usersTotal: 123 This week: 57All time: 9,273 This week: 2Up
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
Nominee
Vote
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  
Name: Julio Vergara <contact>
Classes: 2 packages by
Country: United States United States
Innovation award
Innovation award
Nominee: 2x

Details

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  
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

  Files folder image Files  /  app  
File Role Description
Files folder imageActions (2 directories)
Files folder imageConsole (1 file)
Files folder imageExceptions (1 file)
Files folder imageHttp (1 file, 3 directories)
Files folder imageModels (2 files)
Files folder imageProviders (7 files)
Files folder imageView (1 directory)

  Files folder image Files  /  app  /  Actions  
File Role Description
Files folder imageFortify (5 files)
Files folder imageJetstream (1 file)

  Files folder image Files  /  app  /  Actions  /  Fortify  
File Role Description
  Plain text file CreateNewUser.php Class Class source
  Plain text file PasswordValidationRules.php Class Class source
  Plain text file ResetUserPassword.php Class Class source
  Plain text file UpdateUserPassword.php Class Class source
  Plain text file UpdateUserProfileInformation.php Class Class source

  Files folder image Files  /  app  /  Actions  /  Jetstream  
File Role Description
  Plain text file DeleteUser.php Class Class source

  Files folder image Files  /  app  /  Console  
File Role Description
  Plain text file Kernel.php Class Class source

  Files folder image Files  /  app  /  Exceptions  
File Role Description
  Plain text file Handler.php Class Class source

  Files folder image Files  /  app  /  Http  
File Role Description
Files folder imageControllers (2 files, 1 directory)
Files folder imageLivewire (1 file)
Files folder imageMiddleware (8 files)
  Plain text file Kernel.php Class Class source

  Files folder image Files  /  app  /  Http  /  Controllers  
File Role Description
Files folder imageApi (1 file)
  Plain text file Controller.php Class Class source
  Plain text file RedirectionController.php Class Class source

  Files folder image Files  /  app  /  Http  /  Controllers  /  Api  
File Role Description
  Plain text file UrlController.php Class Class source

  Files folder image Files  /  app  /  Http  /  Livewire  
File Role Description
  Plain text file TopUrls.php Class Class source

  Files folder image Files  /  app  /  Http  /  Middleware  
File Role Description
  Plain text file Authenticate.php Class Class source
  Plain text file EncryptCookies.php Class Class source
  Plain text file PreventRequestsDuringMaintenance.php Class Class source
  Plain text file RedirectIfAuthenticated.php Class Class source
  Plain text file TrimStrings.php Class Class source
  Plain text file TrustHosts.php Class Class source
  Plain text file TrustProxies.php Class Class source
  Plain text file VerifyCsrfToken.php Class Class source

  Files folder image Files  /  app  /  Models  
File Role Description
  Plain text file Url.php Class Class source
  Plain text file User.php Class Class source

  Files folder image Files  /  app  /  Providers  
File Role Description
  Plain text file AppServiceProvider.php Class Class source
  Plain text file AuthServiceProvider.php Class Class source
  Plain text file BroadcastServiceProvider.php Class Class source
  Plain text file EventServiceProvider.php Class Class source
  Plain text file FortifyServiceProvider.php Class Class source
  Plain text file JetstreamServiceProvider.php Class Class source
  Plain text file RouteServiceProvider.php Class Class source

  Files folder image Files  /  app  /  View  
File Role Description
Files folder imageComponents (2 files)

  Files folder image Files  /  app  /  View  /  Components  
File Role Description
  Plain text file AppLayout.php Class Class source
  Plain text file GuestLayout.php Class Class source

  Files folder image Files  /  bootstrap  
File Role Description
  Plain text file app.php Class Class source

  Files folder image Files  /  config  
File Role Description
  Plain text file app.php Class Class source
  Plain text file auth.php Class Class source
  Accessible without login Plain text file broadcasting.php Aux. Auxiliary script
  Accessible without login Plain text file cache.php Aux. Auxiliary script
  Accessible without login Plain text file cors.php Aux. Auxiliary script
  Accessible without login Plain text file database.php Aux. Auxiliary script
  Accessible without login Plain text file filesystems.php Aux. Auxiliary script
  Accessible without login Plain text file fortify.php Aux. Auxiliary script
  Accessible without login Plain text file hashing.php Aux. Auxiliary script
  Accessible without login Plain text file jetstream.php Aux. Auxiliary script
  Plain text file logging.php Class Class source
  Accessible without login Plain text file mail.php Aux. Auxiliary script
  Accessible without login Plain text file queue.php Aux. Auxiliary script
  Plain text file sanctum.php Class Class source
  Accessible without login Plain text file services.php Aux. Auxiliary script
  Accessible without login Plain text file session.php Aux. Auxiliary script
  Accessible without login Plain text file view.php Aux. Auxiliary script

  Files folder image Files  /  database  
File Role Description
Files folder imagefactories (2 files)
Files folder imagemigrations (7 files)
Files folder imageseeders (1 file)

  Files folder image Files  /  database  /  factories  
File Role Description
  Plain text file UrlFactory.php Class Class source
  Plain text file UserFactory.php Class Class source

  Files folder image Files  /  database  /  migrations  
File Role Description
  Plain text file 2014_10_12_000000_create_users_table.php Class Class source
  Plain text file 2014_10_12_100000_...rd_resets_table.php Class Class source
  Plain text file 2014_10_12_200000_..._to_users_table.php Class Class source
  Plain text file 2019_08_19_000000_...iled_jobs_table.php Class Class source
  Plain text file 2019_12_14_000001_...ss_tokens_table.php Class Class source
  Plain text file 2021_10_14_212934_create_urls_table.php Class Class source
  Plain text file 2021_10_16_162118_..._sessions_table.php Class Class source

  Files folder image Files  /  database  /  seeders  
File Role Description
  Plain text file DatabaseSeeder.php Class Class source

  Files folder image Files  /  public  
File Role Description
Files folder imagecss (1 file)
Files folder imagejs (1 file)
  Accessible without login Plain text file .htaccess Data Auxiliary data
  Plain text file index.php Class Class source
  Accessible without login Plain text file mix-manifest.json Data Auxiliary data
  Accessible without login Plain text file robots.txt Doc. Documentation
  Accessible without login Plain text file web.config Data Auxiliary data

  Files folder image Files  /  public  /  css  
File Role Description
  Accessible without login Plain text file app.css Data Auxiliary data

  Files folder image Files  /  public  /  js  
File Role Description
  Accessible without login Plain text file app.js Data Auxiliary data

  Files folder image Files  /  resources  
File Role Description
Files folder imagecss (1 file)
Files folder imagejs (2 files)
Files folder imagelang (1 directory)
Files folder imagemarkdown (2 files)
Files folder imageviews (6 files, 6 directories)

  Files folder image Files  /  resources  /  css  
File Role Description
  Accessible without login Plain text file app.css Data Auxiliary data

  Files folder image Files  /  resources  /  js  
File Role Description
  Accessible without login Plain text file app.js Data Auxiliary data
  Accessible without login Plain text file bootstrap.js Data Auxiliary data

  Files folder image Files  /  resources  /  lang  
File Role Description
Files folder imageen (4 files)

  Files folder image Files  /  resources  /  lang  /  en  
File Role Description
  Accessible without login Plain text file auth.php Aux. Auxiliary script
  Accessible without login Plain text file pagination.php Aux. Auxiliary script
  Accessible without login Plain text file passwords.php Aux. Auxiliary script
  Accessible without login Plain text file validation.php Aux. Auxiliary script

  Files folder image Files  /  resources  /  markdown  
File Role Description
  Accessible without login Plain text file policy.md Data Auxiliary data
  Accessible without login Plain text file terms.md Data Auxiliary data

  Files folder image Files  /  resources  /  views  
File Role Description
Files folder imageapi (2 files)
Files folder imageauth (7 files)
Files folder imagelayouts (2 files)
Files folder imagelivewire (1 file)
Files folder imageprofile (6 files)
Files folder imagevendor (1 directory)
  Accessible without login Plain text file dashboard.blade.php Aux. Auxiliary script
  Accessible without login Plain text file navigation-menu.blade.php Aux. Auxiliary script
  Accessible without login Plain text file policy.blade.php Aux. Auxiliary script
  Accessible without login Plain text file terms.blade.php Aux. Auxiliary script
  Accessible without login Plain text file top-url.blade.php Aux. Auxiliary script
  Accessible without login Plain text file welcome.blade.php Aux. Auxiliary script

  Files folder image Files  /  resources  /  views  /  api  
File Role Description
  Accessible without login Plain text file api-token-manager.blade.php Aux. Auxiliary script
  Accessible without login Plain text file index.blade.php Aux. Auxiliary script

  Files folder image Files  /  resources  /  views  /  auth  
File Role Description
  Accessible without login Plain text file confirm-password.blade.php Aux. Auxiliary script
  Accessible without login Plain text file forgot-password.blade.php Aux. Auxiliary script
  Accessible without login Plain text file login.blade.php Aux. Auxiliary script
  Accessible without login Plain text file register.blade.php Aux. Auxiliary script
  Accessible without login Plain text file reset-password.blade.php Aux. Auxiliary script
  Accessible without login Plain text file two-factor-challenge.blade.php Aux. Auxiliary script
  Accessible without login Plain text file verify-email.blade.php Aux. Auxiliary script

  Files folder image Files  /  resources  /  views  /  layouts  
File Role Description
  Accessible without login Plain text file app.blade.php Aux. Auxiliary script
  Accessible without login Plain text file guest.blade.php Aux. Auxiliary script

  Files folder image Files  /  resources  /  views  /  livewire  
File Role Description
  Accessible without login Plain text file top-urls.blade.php Aux. Auxiliary script

  Files folder image Files  /  resources  /  views  /  profile  
File Role Description
  Accessible without login Plain text file delete-user-form.blade.php Aux. Auxiliary script
  Accessible without login Plain text file logout-other-brows...ions-form.blade.php Aux. Auxiliary script
  Accessible without login Plain text file show.blade.php Aux. Auxiliary script
  Accessible without login Plain text file two-factor-authentication-form.blade.php Aux. Auxiliary script
  Accessible without login Plain text file update-password-form.blade.php Aux. Auxiliary script
  Accessible without login Plain text file update-profile-inf...tion-form.blade.php Aux. Auxiliary script

  Files folder image Files  /  resources  /  views  /  vendor  
File Role Description
Files folder imagejetstream (2 directories)

  Files folder image Files  /  resources  /  views  /  vendor  /  jetstream  
File Role Description
Files folder imagecomponents (28 files)
Files folder imagemail (1 file)

  Files folder image Files  /  resources  /  views  /  vendor  /  jetstream  /  components  
File Role Description
  Accessible without login Plain text file action-message.blade.php Aux. Auxiliary script
  Accessible without login Plain text file action-section.blade.php Aux. Auxiliary script
  Accessible without login Plain text file application-logo.blade.php Aux. Auxiliary script
  Accessible without login Plain text file application-mark.blade.php Aux. Auxiliary script
  Accessible without login Plain text file authentication-card-logo.blade.php Aux. Auxiliary script
  Accessible without login Plain text file authentication-card.blade.php Aux. Auxiliary script
  Accessible without login Plain text file banner.blade.php Aux. Auxiliary script
  Accessible without login Plain text file button.blade.php Aux. Auxiliary script
  Accessible without login Plain text file checkbox.blade.php Aux. Auxiliary script
  Accessible without login Plain text file confirmation-modal.blade.php Aux. Auxiliary script
  Accessible without login Plain text file confirms-password.blade.php Aux. Auxiliary script
  Accessible without login Plain text file danger-button.blade.php Aux. Auxiliary script
  Accessible without login Plain text file dialog-modal.blade.php Aux. Auxiliary script
  Accessible without login Plain text file dropdown-link.blade.php Aux. Auxiliary script
  Accessible without login Plain text file dropdown.blade.php Aux. Auxiliary script
  Accessible without login Plain text file form-section.blade.php Aux. Auxiliary script
  Accessible without login Plain text file input-error.blade.php Aux. Auxiliary script
  Accessible without login Plain text file input.blade.php Aux. Auxiliary script
  Accessible without login Plain text file label.blade.php Aux. Auxiliary script
  Accessible without login Plain text file modal.blade.php Aux. Auxiliary script
  Accessible without login Plain text file nav-link.blade.php Aux. Auxiliary script
  Accessible without login Plain text file responsive-nav-link.blade.php Aux. Auxiliary script
  Accessible without login Plain text file secondary-button.blade.php Aux. Auxiliary script
  Accessible without login Plain text file section-border.blade.php Aux. Auxiliary script
  Accessible without login Plain text file section-title.blade.php Aux. Auxiliary script
  Accessible without login Plain text file switchable-team.blade.php Aux. Auxiliary script
  Accessible without login Plain text file validation-errors.blade.php Aux. Auxiliary script
  Accessible without login Plain text file welcome.blade.php Aux. Auxiliary script

  Files folder image Files  /  resources  /  views  /  vendor  /  jetstream  /  mail  
File Role Description
  Accessible without login Plain text file team-invitation.blade.php Aux. Auxiliary script

  Files folder image Files  /  routes  
File Role Description
  Plain text file api.php Class Class source
  Accessible without login Plain text file channels.php Example Example script
  Accessible without login Plain text file console.php Example Example script
  Plain text file web.php Class Class source

  Files folder image Files  /  tests  
File Role Description
Files folder imageFeature (14 files)
Files folder imageUnit (1 file)
  Plain text file CreatesApplication.php Class Class source
  Plain text file TestCase.php Class Class source

  Files folder image Files  /  tests  /  Feature  
File Role Description
  Plain text file ApiTokenPermissionsTest.php Class Class source
  Plain text file AuthenticationTest.php Class Class source
  Plain text file BrowserSessionsTest.php Class Class source
  Plain text file CreateApiTokenTest.php Class Class source
  Plain text file DeleteAccountTest.php Class Class source
  Plain text file DeleteApiTokenTest.php Class Class source
  Plain text file EmailVerificationTest.php Class Class source
  Plain text file ExampleTest.php Class Class source
  Plain text file PasswordConfirmationTest.php Class Class source
  Plain text file PasswordResetTest.php Class Class source
  Plain text file ProfileInformationTest.php Class Class source
  Plain text file RegistrationTest.php Class Class source
  Plain text file TwoFactorAuthenticationSettingsTest.php Class Class source
  Plain text file UpdatePasswordTest.php Class Class source

  Files folder image Files  /  tests  /  Unit  
File Role Description
  Plain text file ExampleTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:123
This week:57
All time:9,273
This week:2Up
For more information send a message to info at phpclasses dot org.