Skip to content

cristian-sudo/LaravelEncodingUrl

Repository files navigation

URL Shortening Service

This project implements a URL shortening service using PHP and Laravel. It provides endpoints to encode long URLs into short URLs and decode short URLs back to their original form.

Features

  • Encode long URLs into short, unique URLs.
  • Decode short URLs back to their original URLs.
  • In-memory storage of URL mappings using Laravel's caching system.
  • Structured JSON responses for all API endpoints.
  • Includes a Makefile for running tests and checking code standards.

Requirements

  • PHP 8.3 or higher
  • Composer
  • Laravel 11.x
  • Laravel Valet for local development

Installation

  1. Clone the Repository:

    git clone git@github.com:cristian-sudo/LaravelEncodingUrl.git
    cd LaravelEncodingUrl
  2. Install Dependencies:

    Use Composer to install the required PHP dependencies:

    composer install
  3. Environment Setup:

    Copy the .env.example file to .env and configure your environment variables as needed:

    cp .env.example .env

    Generate an application key:

    php artisan key:generate
  4. Serve with Laravel Valet:

    If you're using Laravel Valet for local development, navigate to your project directory and link it with Valet:

    valet link laravel-url-shortener
    valet secure laravel-url-shortener

    Your application will be accessible at https://laravel-url-shortener.test.

Usage

Encode URL

  • Endpoint: /api/encode
  • Method: POST
  • Request Body: JSON with a url field containing the long URL to be shortened.

Example Request:

{
  "url": "https://www.thisisalongdomain.com/with/some/parameters?and=here_too"
}

Example Response:

{
  "status": "success",
  "message": "URL encoded successfully",
  "data": {
    "short_url": "https://laravel-url-shortener.test/GeAi9K"
  },
  "errors": [],
  "statusCode": 200
}

Decode URL

  • Endpoint: /api/decode
  • Method: POST
  • Request Body: JSON with a short_url field containing the short URL to be decoded.

Example Request:

{
  "short_url": "https://laravel-url-shortener.test/GeAi9K"
}

Example Response:

{
  "status": "success",
  "message": "URL decoded successfully",
  "data": {
    "original_url": "https://www.thisisalongdomain.com/with/some/parameters?and=here_too"
  },
  "errors": [],
  "statusCode": 200
}

Testing and Code Quality

The project includes a Makefile to facilitate testing and code quality checks using PHP_CodeSniffer.

Run Tests

To run the tests, use the following command:

make test

Code Quality Checks

  • Check Code Standards:

    Run PHP_CodeSniffer to check code standards:

    make phpcs
  • Fix Code Standards:

    Run PHP_CodeBeautifier and Fixer to automatically fix code standards issues:

    make phpcbf
  • Fix and Check:

    Run both the fixer and the checker:

    make fix-and-check

License

This project is open-source and available under the MIT License.

Here is a link to the project documentation: LaravelEncodingUrl

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages