mirror of
https://github.com/michivonah/python.git
synced 2025-12-22 20:46:29 +01:00
create simple api & take some notes
This commit is contained in:
parent
43564dc7c8
commit
48b7dcd892
2 changed files with 28 additions and 0 deletions
12
api/api.md
Normal file
12
api/api.md
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
# API in python
|
||||||
|
|
||||||
|
Required python packages
|
||||||
|
- fastapi
|
||||||
|
- uvicorn
|
||||||
|
- flask
|
||||||
|
|
||||||
|
Install with pip3 install <PACKAGENAME>
|
||||||
|
|
||||||
|
|
||||||
|
## Sources
|
||||||
|
- https://youtu.be/zsYIw6RXjfM
|
||||||
16
api/main.py
Normal file
16
api/main.py
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
from flask import Flask, request, jsonify, redirect
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
@app.route("/hello")
|
||||||
|
def helloWorld():
|
||||||
|
return "Hello World"
|
||||||
|
|
||||||
|
@app.route("/<slug>")
|
||||||
|
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)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue