From 1e69590eaad61fc8da9f011b5b9e77419771b871 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Katariina=20J=C3=A4rvenm=C3=A4ki?= Date: Sun, 1 Mar 2026 11:03:51 +0200 Subject: [PATCH] Add basic FastAPI structure and random string generator --- .gitignore | 2 ++ README.md | 11 +++++++++-- app/main.py | 9 +++++++++ app/utils.py | 7 +++++++ 4 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 app/main.py create mode 100644 app/utils.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8750bee --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +app/__pycache__ +venv/ \ No newline at end of file diff --git a/README.md b/README.md index a3c11cb..9fb714a 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,9 @@ -# url-shortener -Url-shortener project to showcase python use +# URL-shortener +URL-shortener project to showcase python use + +## Run locally +```bash +uvicorn app.main:app --reload +``` +Then check: +http://127.0.0.1:8000 \ No newline at end of file diff --git a/app/main.py b/app/main.py new file mode 100644 index 0000000..d855f15 --- /dev/null +++ b/app/main.py @@ -0,0 +1,9 @@ +from fastapi import FastAPI, HTTPException +from fastapi.responses import RedirectResponse + +app = FastAPI() + +@app.get("/") +def home(): + return {"message": "URL Shortener API"} + \ No newline at end of file diff --git a/app/utils.py b/app/utils.py new file mode 100644 index 0000000..785e0b4 --- /dev/null +++ b/app/utils.py @@ -0,0 +1,7 @@ +import string +import random + +def generate_short_code(length=6): + characters = string.ascii_letters + string.digits + return ''.join(random.choice(characters) for _ in range(length)) + \ No newline at end of file