While in the directory enter the following line: flask run -p <port>
POST - http://127.0.0.1/shorten
POST - http://127.0.0.1/shorten/<user_id>
Body: must include "url"
{
"url": "www.hello.com"
}
Response:
{
"short_url": "http://127.0.0.1/3GSJrD"
}
GET - http://127.0.0.1/<suffix_hash>
POST - http://127.0.0.1/sign_up
Body: must include "email" and "name"
{
"email": "[email protected]",
"name": "lior"
}
POST - http://127.0.0.1/log_in
Body: must include "email"
{
"email": "[email protected]",
}
GET - http://127.0.0.1/shorten/<user_id>
Response:
{
"url_data": [
{
"short_url:" "http://127.0.0.1/5gDZEF",
"original_url": "https://github.com/LiorSB/url-shortener/tree/feature/backend-db-ds",
"creation_date": "2022-10-08T23:14:47.558657",
"expiration_date": "2027-10-07T23:14:47.558657"
},
{
"short_url": "http://127.0.0.1/1bqOQw",
"original_url": "https://www.w3schools.com/python/python_mongodb_find.asp",
"creation_date": "2022-10-08T23:56:03.839908",
"expiration_date": "2027-10-07T23:56:03.839908"
}
]
}
The load balancer used in this system is HAProxy with the RoundRobin
strategy.
Guide links:
flask_caching
has been used with the SimpleCache
cache type. Flask Caching Docs
MongoDB has been used as the DB and its collections have been sharded by their ID with the hashed
strategy.
How it was built: Deploy a Sharded Cluser
Shortening URLs can be handy where there is a limit for the number of characters, for example: chat boxes of twitter, instagram, facebook and other platforms.
-
Create front-end with React.
-
Create back-end with Python.
-
Create database with MongoDB.
-
Generate a short URL from a long URL.
-
Encode short URL path.
-
Once a short URL has been entered to the address bar, redirect to the original (long) URL.
-
Handle expired URL’s.
-
Store: short URL, long URL, creation date, expiration date and the user to the DB.
-
Load balancer.
-
Create premium users.
-
Make the search function as efficient as possible to prevent latency issues.
-
Premium users can view their URLs history.
- Premium users have a longer expiration time.
- Premium users can choose a path to the short URL by following a set of rules that match the format.