Skip to content

Laravel based API to shorten URLs and share them easily. Redirects to the real URL by entering a short URL generated by the API

Notifications You must be signed in to change notification settings

Claw-Hammer/ushort

Repository files navigation

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

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

  php artisan migrate --seed

A default user is created with the following credentials:

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

API End-Points

/api/v1/url/shortener

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

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

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

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

/api/v1/url/top

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

/api/v1/url/real

This will return the real Url that the provided short url points to, you need to send a GET request with your short url as a parameter on the url api call as follows:

  {your-domain}/api/v1/url/real?url={your-short-url}

if succeed, the request will return 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

Required and pending 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.

About

Laravel based API to shorten URLs and share them easily. Redirects to the real URL by entering a short URL generated by the API

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published