Your mission, should you choose to accept it, is to build a microservice called shorty
,
which supports two URL shortening providers: bit.ly and tinyurl.com.
You don't need to actually sign up to these providers, just implement their API. The
service exposes a single endpoint: POST /shortlinks
. The endpoint should receive
JSON with the following schema:
param | type | required | description |
---|---|---|---|
url | string | Y | The URL to shorten |
provider | string | N | The provider to use for shortening |
The response should be a Shortlink
resource containing:
param | type | required | description |
---|---|---|---|
url | string | Y | The original URL |
link | string | Y | The shortened link |
For example:
{
"url": "https://example.com",
"link": "https://bit.ly/8h1bka"
}
You are free to decide how to pick between the providers if one is not requested and what your fallback strategy is in case your primary choice fails. Your endpoint needs to return a JSON response with a sensible HTTP status in case of errors or failures.
- Create a Python env (using Python 3.6+) and install the requirements.
- Build the
POST /shortlinks
endpoint. We've provided a skeleton API usingflask
. - Write some tests. We've provided a test blueprint using
pytest
.
Flask
: http://flask.pocoo.org/pytest
: http://pytest.org/latest/virtualenvwrapper
: https://virtualenvwrapper.readthedocs.io/en/latest/HTTP statuses
: https://httpstatuses.com/
bitly & tinyurl
: Implemented tinyurl, bitly service classes, added a base class to combine them.POST /shortlinks
: Implemented the endpoint where the above classes are called based on user's input.error handling
: Implemented an error handler class and objects.schema and provider control
: Set up a default provider if none is chosen. Implemented fallback strategy.unit testing
: Functions are tested.functional testing
: Flask server is tested.virtualenvwrapper
: Script added.