From 48b7dcd892ea35f9cf274315106db10890cc1264 Mon Sep 17 00:00:00 2001 From: michivonah Date: Sun, 27 Aug 2023 16:43:59 +0200 Subject: [PATCH] create simple api & take some notes --- api/api.md | 12 ++++++++++++ api/main.py | 16 ++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 api/api.md create mode 100644 api/main.py diff --git a/api/api.md b/api/api.md new file mode 100644 index 0000000..7afb4df --- /dev/null +++ b/api/api.md @@ -0,0 +1,12 @@ +# API in python + +Required python packages +- fastapi +- uvicorn +- flask + +Install with pip3 install + + +## Sources +- https://youtu.be/zsYIw6RXjfM \ No newline at end of file diff --git a/api/main.py b/api/main.py new file mode 100644 index 0000000..9d70a86 --- /dev/null +++ b/api/main.py @@ -0,0 +1,16 @@ +from flask import Flask, request, jsonify, redirect + +app = Flask(__name__) + +@app.route("/hello") +def helloWorld(): + return "Hello World" + +@app.route("/") +def shortUrl(slug): + #return f"This is a short url! Your slug: {slug}" + destination = f"https://www.google.com/search?q={slug}" + return redirect(destination, code=302) + +if __name__ == "__main__": + app.run(debug=True) \ No newline at end of file