This service implements an endpoint for generating shortened links. Following endpoints are supported:
Generate site identifier identifying provided URL:
$ curl -XPOST "localhost:5001/api/v1/shorten/https://gooogle.com?format=json"
{"status": "OK", "request_url": "https://gooogle.com", "identifier": 1204225829}
Retrieving URL from provided identifier:
$ curl "localhost:5001/api/v1/lookup/1204225829?format=json"
{"status": "OK", "request_url": "https://gooogle.com", "identifier": "1204225829"}
Performing HTTP redirect when identifier is supplied in apps base path:
url "localhost:5001/1204225829" -v
..
< HTTP/1.0 302 FOUND
< Content-Type: text/html; charset=utf-8
< Location: https://gooogle.com
...
- Given time constraints, an in memory python dictionary object is used to store mapping of URLs to generated identifiers
- Lookup and shorten endpoint can be provided with optional ?format=<json|xml> query parameter which them generates json or XML output. Json is default in cases when no format parameter is supplied or format != <json|xml>
- Please refer to comments in main app.py file, it contains more insight into app's functionality
The application is intended to run in a docker container. To build:
docker build --tag url-shortener .
The application is then run exposing an example port 5001 as it's API endpoint:
docker run --publish 5001:5001 url-shortener