https://roadmap.sh/projects/url-shortening-service
- Laravel php framework
- Sqlite light weight database
git clone https://github.com/projecthanif/roadmapurlshortner
cd roadmapurlshortner
composer install
copy .env.example .env
php artisan key:generate
php artisan migrate
php artisan serve
Create Short URL Create a new short URL using the POST method
POST /api/v1/shorten
{
"url": "https://www.example.com/some/long/url"
}
The endpoint should validate the request body and return a 201 Created status code with the newly created short URL i.e.
"id": "1",
"url": "https://www.example.com/some/long/url",
"shortCode": "abc123",
"createdAt": "2021-09-01T12:00:00Z",
"updatedAt": "2021-09-01T12:00:00Z"
}
Retrieve the original URL from a short URL using the GET method
GET /api/v1/shorten/abc123
The endpoint should return a 200 OK status code with the original URL i.e.
{
"id": "1",
"url": "https://www.example.com/some/long/url",
"shortCode": "abc123",
"createdAt": "2021-09-01T12:00:00Z",
"updatedAt": "2021-09-01T12:00:00Z"
}
Update an existing short URL using the PUT method
PUT /api/v1/shorten/abc123
{
"url": "https://www.example.com/some/updated/url"
}
The endpoint should validate the request body and return a 200 OK status code with the updated short URL i.e.
{
"id": "1",
"url": "https://www.example.com/some/updated/url",
"shortCode": "abc123",
"createdAt": "2021-09-01T12:00:00Z",
"updatedAt": "2021-09-01T12:30:00Z"
}
Delete an existing short URL using the DELETE method
DELETE /api/v1/shorten/abc123
Get statistics for a short URL using the GET method
GET /api/v1/shorten/abc123/stats
The endpoint should return a 200 OK status code with the statistics i.e.
{
"id": "1",
"url": "https://www.example.com/some/long/url",
"shortCode": "abc123",
"createdAt": "2021-09-01T12:00:00Z",
"updatedAt": "2021-09-01T12:00:00Z",
"accessCount": 10
}