Shotr is a URL shortening service that allows you to create shorter versions of long URLs, making them easier to share and manage.
This project provides a web-based URL shortening service along with a RESTful API for shortening URLs programmatically. With Shotr, you can create concise and easy-to-share versions of long URLs, making it convenient for sharing links in emails, social media, and more.
These instructions will help you get a copy of the Shotr project up and running on your local machine for development and testing purposes.
Before you begin, ensure you have met the following requirements:
- Clone the repository:
git clone https://github.com/manishram/short.git
Navigate to the project directory:
cd shotr
Install PHP dependencies:
composer install
Install JavaScript dependencies:
npm install
Build Vite:
npm run build
Configure your database settings in .env file.
Generate the application key:
php artisan key:generate
Run database migrations and seed the database:
php artisan migrate --seed
Start the development server:
php artisan serve
The application should now be running on http://localhost:8000.
To shorten a URL using the API, send a POST request to the /api/v1/shorten-url
endpoint with a JSON payload containing the destination parameter.
POST /api/v1/shorten-url
{
"destination": "https://example.com"
}
Example Response:
{
"destination": "https://example.com",
"slug": "abcde",
"updated_at": "2021-09-10T23:52:11.000000Z",
"created_at": "2021-09-10T23:52:11.000000Z",
"id": 1,
"shortened_url": "http://localhost:8000/ab5d7"
}
If the request is invalid or a non-valid URL is provided, the API will return a validation error response. Example Validation Error Response:
{
"message": "The given data was invalid.",
"errors": {
"destination": [
"The destination field is required.",
"The destination must be a valid URL."
]
}
}
Shotr is open-sourced software licensed under the MIT license.