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.
- 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.
- PHP 8.3 or higher
- Composer
- Laravel 11.x
- Laravel Valet for local development
-
Clone the Repository:
git clone git@github.com:cristian-sudo/LaravelEncodingUrl.git cd LaravelEncodingUrl -
Install Dependencies:
Use Composer to install the required PHP dependencies:
composer install
-
Environment Setup:
Copy the
.env.examplefile to.envand configure your environment variables as needed:cp .env.example .env
Generate an application key:
php artisan key:generate
-
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.
- Endpoint:
/api/encode - Method: POST
- Request Body: JSON with a
urlfield 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
}- Endpoint:
/api/decode - Method: POST
- Request Body: JSON with a
short_urlfield 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
}The project includes a Makefile to facilitate testing and code quality checks using PHP_CodeSniffer.
To run the tests, use the following command:
make test-
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
This project is open-source and available under the MIT License.
Here is a link to the project documentation: LaravelEncodingUrl