https://github.com/bybenpuls/url-shortener
A simple async URL Shortener on Python with Database (Redis, Postgres)
https://github.com/bybenpuls/url-shortener
api asyncio asyncpg css database fastapi html javascript js postgres postgresql pure-javascript python python3 redis url url-shortener uvicorn web
Last synced: about 2 months ago
JSON representation
A simple async URL Shortener on Python with Database (Redis, Postgres)
- Host: GitHub
- URL: https://github.com/bybenpuls/url-shortener
- Owner: byBenPuls
- License: apache-2.0
- Created: 2024-07-21T14:31:38.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-05T02:57:40.000Z (over 1 year ago)
- Last Synced: 2026-01-03T11:28:16.936Z (5 months ago)
- Topics: api, asyncio, asyncpg, css, database, fastapi, html, javascript, js, postgres, postgresql, pure-javascript, python, python3, redis, url, url-shortener, uvicorn, web
- Language: Python
- Homepage: https://bybenpuls.github.io/url-shortener/
- Size: 73.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
### Content:
* **[🔥 Features](#-features)**
* **[💡 Installation](#-installation)**
## 🔥 Features
### 🔷 Asynchronous app
App built with FastAPI.
It is a high performance framework In the process of writing the application,
only asynchronous programming was used (except cpu-bound operation).
All i/o-bound operations are asynchronous.
### 📁 Database entry (postgres, redis)
App using a postgres database. All information about links is recorded in it. The Database contains one table
| id | original | modified |
|:---|:--------------------:|---------------------:|
| 1 | https://google.com/ | mrknROpKuogikvRGDiHX |
| 2 | https://example.com/ | jYJKeSjnDcOvJwItGrZs |
The table is automatically created (if the table does not exist) every time when starting app.
It's possible because of
`pg_table_builder` [module](https://github.com/byBenPuls/table-builder-pg).
After successful record in postgres database data save in a redis database.
Data keep in key=value format in RAM machine.
It's really fast!
### 📱 Adaptive website
Website created with a Bootstrap framework. Bootstrap supports mobile screen size.
### ⚡ Fast
The application checks whether the data is in the cache.
For this reason, data is rapid and redirection occurs unnoticed.
### ️🛡️ Duplicate link protection
App has protection that compares original and modified links. It'd protect from infinite creating same links.
### ⚙️ API
The application allows you to send POST HTTP requests to receive a modified link.
**For example:**
Request:
```python
import requests
requests.post(
'/',
json={"original_url": "https://google.com/"})
```
Response:
```python
{"endpoint": "https:///mrknROpKuogikvRGDiHX/"}
```
## 💡 Installation
First, install a virtual environment `py -m venv venv`.
Next, you need activating venv. Windows: `.\Scripts\activate` Linux: `source bin/activate`.
Most Python IDEs can on one's own create virtual environment. Also, you need to create env variable.
You can use dotenv or your IDE. `DB_CONNECTION_STRING=postgres://...`
Then you need to install all requirements:
move to the root directory of the project and type `pip install -r requirements.txt`.
For launch FastAPI I'm using `uvicorn`.
You can choose parameters of launch (host, port) if it is necessary.
After this, you can start a project, for example `py setup.py`.