Shorty is an application that receives your long, ugly urls and ask its provider to make it smaller and prettier.
Providers are external services that specialize in url shortening. When you ask Shorty to shorten your url, Shorty sends a request to one of those providers in order to shorten.
You can either choose which provider Shorty should use or let Shorty pick one for you.
You can run it locally either with python with virtualenv
or with docker
$ ./run_with_virtual_env.sh
# build docker image
$ docker built -t shorty:latest .
# run the docker image
$ docker run -p <the-port-you-want>:5000 shorty
Great job! Now you just need to send to Shorty some requests to execute. The request should look like the above
{
"url": "the url you want to shorten",
"provider": "the provider that will shorten the url (optional)"
}
If you send a valid request the response would look something like this:
{
"data": {
"url": "https://example.com",
"link": "https://bit.ly/8h1bka",
}
}
If you make any invalid request, Shorty will try his best to let you know what needs to be done. The error format looks like this:
{
"error": {
"status": "http status code",
"code": "application specific error code",
"detail": "detail message for the error"
}
}
Just run the tests 😅 To run the test just execute:
$ py.test
Shorty's architecture is based on Robert's C. Martin Clean Architecture.
The /postlink
executes the ShortenUseCase
with the given request.
In the execution, the use case checks if the request is valid and if it is,
it just retrieves the provider from the provider factory and the provider does
the shortening.
If any errors arise during the shorten use case, the appropriate shorty exception will be raised and returned.
Flask
: http://flask.pocoo.org/pytest
: http://pytest.org/latest/virtualenvwrapper
: https://virtualenvwrapper.readthedocs.io/en/latest/HTTP statuses
: https://httpstatuses.com/