Created
December 8, 2023 10:50
-
-
Save nowiwr01w/820fa8c5048f57de69aae6790b46220d to your computer and use it in GitHub Desktop.
Simple API with Flask (local)
This file contains 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, jsonify, request | |
from flask_cors import CORS | |
class User: | |
def __init__(self, id, name): | |
self.id = id | |
self.name = name | |
app = Flask(__name__) | |
CORS(app) | |
users = [ | |
{"id": 1, "name": "Alice"}, | |
{"id": 2, "name": "Bob"}, | |
{"id": 3, "name": "Charlie"} | |
] | |
@app.route('/users', methods=['GET']) | |
def get_users(): | |
return jsonify(users) | |
if __name__ == '__main__': | |
app.run(debug=True, port=5001) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment