This simple api service provides two endpoints for shortening then retrieving a URL.
POST /encode
Takes a url and a domain as form-data in the request. The url is the url to be shortened, the domain is used to generate the shortened url endpoint.
GET /decode/{code}
The {code} value included in the url is the one generated by the /encode
endpoint. This endpoint retrieves the original url.
The first step is to copy the .env.example
and create your own .env
file.
Next, install laravel locally by running the following command:
composer install
Now create the database and run the seeder that creates the user table with the single atarim user for the purposes of this excercise:
php artisan migrate --seed
And finally run the install command to create your new api authentication token and setup test sqlite instance.
Please make sure you take a note of the token returned by the command.
php artisan install:api
This API implememnts a simple authorisation token approach which is implemented by an Authorization
header which restricts access to authorised users only. Please ensure that all requests made to the api endpoints include your api token that you generated in the last step of the installation instructions. Simply add the Authorization header as per the example below
Authorization: Bearer ********
I have included a Postman collection for your convenience. It can be found in the root of this project.
To perform the tests on the two endpoints simply run the tests:
php artisan test