This is a server for generating short URL. Users first provide their original long URL and this API generate a shorter one for users. Later on, users can use this URL to visit their origin website.
- Framework: FastAPI
- Database: MongoDB
- Container: Docker
- Unit test: pytest
- Enter long URL and generate short URL
- Use short URL to redirect to long URL
- Copy the generated short URL
If you run this app locally, you will need follow the installation: MongoDB. After downloading, I use macOS as an example:
- Start MongoDB
brew services start mongodb-community- Stop MongoDB
brew services stop mongodb-community- Clone this repository
git clone https://github.com/ferygood/shortURL.git cd shortURL - Create a virtual environment and install dependencies
python -m venv venv source venv/bin/activate pip install -r requirements.txt
Run the app
uvicorn main:app --reloadAfter running the app, you can paste http://127.0.0.1:8000/ in your browser:

you can also use tools such as cURL to interact with the api For example:
curl -X POST "http://localhost:8000/api/shorten" -H "Content-Type: application/json" -d '{"long_url": "https://www.google.com"}'
use the shorten url. Let says you receive a short URL: abcd123,
curl -X GET "http://localhost:8000/abcd123"