This is the backend for the URL shortener application, built with Laravel.
-
Clone the repository
sh git clone https://github.com/luissanchez0305/laravel-url-shortener.git cd laravel-url-shortener
-
Install dependencies
composer install
-
Set up environment variables Copy the .env.example file to .env and update the environment variables as needed.
sh Copiar código cp .env.example .env
-
Generate application key
php artisan key:generate
-
Store sessions on the DB
php artisan session:table
-
Run migrations
php artisan migrate
-
Install Sanctum for API authentication
php artisan install:api
-
Start the Laravel development server
php artisan serve
The application will be available at http://127.0.0.1:8000.
-
POST /api/shorten: Shortens a URL.
Request body: { "original_url": "https://example.com" } Response: { "id": 1, "original_url": "https://example.com", "shortened_url": "abcd1234", "created_at": "...", "updated_at": "..." }
-
GET /api/{shortened_url}: Redirects to the original URL.
Response: Redirects to the original URL.
```
php artisan test
```