Simple URL shortener using FastAPI, SQLAlchemy and SQLite3
1.3K
A minimalist and lightweight URL shortener using FastAPI and SQLAlchemy and SQLite3.
Shortgic requires few Python libraries such as FastAPI, SQLAlchemy for the database integration and Uvicorn for serving the application.
$ docker run -d -n shortgic -p 8000:8000 smartgic/shortgic:latest
As any FastAPI project, a Swagger documention is available at http://127.0.0.1:8000/docs
Create a basic URL shortened.
$ curl -s -X POST http://127.0.0.1:8000 -d '{"target": "https://smartgic.io"}'
{
"link": "BEN9S"
}
Create an URL shortened with extras information, extras must be a JSON dictionary.
$ curl -s -X POST http://127.0.0.1:8000 -d '{"target": "https://smartgic.io", "extras": {"version": "0.2b-1", "validated": true}}'
{
"link": "UY9JN"
}
Redirection to the target URL, the -L option should be used with curl to follow the 302 redirection.
$ curl -s -X GET http://127.0.0.1:8000/UY9JN -L
Get link information, this will output the target and the extras information.
$ curl -s -X GET http://127.0.0.1:8000/UY9JN/info
{
"target": "https://smartgic.io",
"extras": {
"version": "0.2b-1",
"validated": true
}
}
Remove permanently an URL shortened from the database.
$ curl -s -X DELETE http://127.0.0.1:8000/UY9JN
Content type
Image
Digest
sha256:002770bc2…
Size
124.9 MB
Last updated
about 1 year ago
docker pull smartgic/shortgic