Created
March 26, 2025 09:14
-
-
Save noahjames404/e5b95c1a9a0f99a23a9f9732bda55fad to your computer and use it in GitHub Desktop.
api demo in flask environment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from flask import Flask, request | |
| app = Flask(__name__) | |
| @app.route("/") | |
| def hello_world(): | |
| searchword = request.args.get('key', '') | |
| return { | |
| "searchword": searchword, | |
| "username": "ivan", | |
| "first_name": "ivan", | |
| "last_name": "santos", | |
| "hobbies": "badminton" | |
| } | |
| @app.route("/sum") | |
| def sum(): | |
| a = request.args.get('a', 0) | |
| b= request.args.get('b',0) | |
| return { | |
| "sum": float(a) + float(b) | |
| } | |
| @app.route("/authenticate", methods=["POST"]) | |
| def authenticate(): | |
| username = request.form['username'] | |
| password = request.form['password'] | |
| res = False | |
| if(username == "ivan" and password == "ivan"): | |
| res = True | |
| return { | |
| "username": username, | |
| "password": password, | |
| "authenticated": res | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment