mirror of
https://github.com/michivonah/python.git
synced 2025-12-22 20:46:29 +01:00
create concept for url shortener
This commit is contained in:
parent
48b7dcd892
commit
cfce308a2e
1 changed files with 17 additions and 0 deletions
17
api/url-shortener.py
Normal file
17
api/url-shortener.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
from flask import Flask, request, jsonify, redirect
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route("/create/<slug>")
|
||||
def createNew(slug):
|
||||
return f"New request registerd for /{slug}"
|
||||
|
||||
@app.route("/<slug>")
|
||||
def shortUrl(slug):
|
||||
destination = f"https://www.example.com/{slug}"
|
||||
return redirect(destination, code=302)
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(debug=True)
|
||||
|
||||
# random base64 string: openssl rand -base64 24
|
||||
Loading…
Add table
Add a link
Reference in a new issue