Add basic FastAPI structure and random string generator
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
app/__pycache__
|
||||
venv/
|
||||
@@ -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
|
||||
@@ -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"}
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user