Setup up an api endpoint to take a websites url (eg: https://someapp.com/catalog/app/lists) and returns an shortened URL such as https://someapp.com/GeAi9P.
- python 3.11.6
-
Clone repo
git clone https://github.com/smetroid/URLShortening.git
-
Change into URLShortening
cd URLShortening
-
Create the virtual environment
python -m venv .venv
-
Source the virtual env
source .venv/bin/activate
-
Install python packages
pip install -r requirements.txt
-
Start the flask app
waitress-serve 'shorturl:shorturl'
-
Shortening a url using curl
curl --header "Content-Type: application/json" -X POST localhost:8080/encode --data '{"url": "https://www.yahoo.com/news/dog-adopted-7-years-pennsylvania-210548824.html"}'
Result:
{"id":"4LoFSC","short_url":"https://www.yahoo.com/4LoFSC"}
-
Retrieving original URL using the id above
curl --header "Content-Type: application/json" -X POST localhost:5000/decode --data '{"id": "rcj3GA"}'
Result:
{"id":"4LoFSC","original_url":"https://www.yahoo.com/news/dog-adopted-7-years-pennsylvania-210548824.html"}
-
Export the apps
export FLASK_APP=shorturl.py
-
Start development server
flask run
-
Running tests
pytest
I've included my .vscode/settings
which includes a launch.json
file which you can use to run the VSCode debugger. It may need to be updated based on your Operating System.