An open API service indexing awesome lists of open source software.

https://github.com/modelizer/werkspot


https://github.com/modelizer/werkspot

Last synced: 9 months ago
JSON representation

Awesome Lists containing this project

README

          

## Werkspot Assignment (Application to Build Short URLs)

### Technology used:
1. PHP 8.0
2. Laravel 8
3. Docker
4. RESTful API

### Some Key Explanations:
1. Laravel is use to demonstrate as much understanding as possible. It comes out of the box with all the toolkit required. Such as docker, frontend components, faker and other utility which saves a lot of time.
2. RESTful API is used instead of GraphQL because there was no complexity to fetch complex data. As REST API has a solid standard to make a strict rule for a user to follow. This helps us to put some default validation.
3. As time was consumed in simplifying the short URL algorithm that's why the frontend task is pending. Otherwise, VueJS would be used because it is shipped by default with the Laravel framework.

### What has been done?
1. Added Workspot URL shortener functionality.
1. Added Bitly integration. The default token is already present in `.env.sample` file.
1. Added 30/70 AB testing. 30% is Bitly API and 70% is our API.
1. Important testcases are written but there are some missing.

### Setup:
1. Get git clone `git clone https://github.com/Modelizer/werkspot.git`
1. Copy `.env.sample` to `.env`
1. Run `vendor/bin/sail up` to initialise the container. In background it uses docker-compose file.
1. Login to container `docker-compose exec laravel.test bash`
1. Run `composer install` inside the container. If some how you are facing any issue then please run `composer install` on your host machine.
1. Run phpunit to see all the testcases are passing. `vendor/bin/phpunit`

### Some Keyfiles to look into it:
1. Werkspot url compressor is treated as a library and extracted to its folder `modules/CompressUrl`
1. Middleware is a concept in the Laravel which help to any important thing with the request before sending it to Controller. Here is use `App\Http\Middleware\SplitTesting` middleware to swap URL compressor driver according ot 30/70 AB testing.
1. By default `WerkspotUrlDriver` is bind with `UrlCompressorDriverContract` interface. Please see `AppServiceProvider` class.
1. `BitlyUrlDriver` acts as an adaptor for `shivella/laravel-bitly` composer package.

### Shorter URL mechanism:
1. Base62 character methodology is used.
1. Two simplify this mechanism two classes are created. One to handle all the Base62 letters and their indexes and 2nd class to generate the url. Please see `Werkspot\CompressUrl\Base62` and `Werkspot\CompressUrl\UrlGenerator`.
1. The next short URL is generated by using the previous URL.
1. As per the assignment, there is no complexity related to storage. Therefore Redis is used to store the URLs as it also helps us to be faster retrieving.
1. All the URLs are saved in the URL's Redis database.

### APIs:
1. [POST] `http://localhost/api/url?url=http://convert-this-url-to-short-url.com` This API will create a short url.
2. Use the generated short url to test for example `http://localhost/s`. It will give not found page when url does not exists.