Skip to content

Instantly share code, notes, and snippets.

@nowiwr01w
Created December 8, 2023 10:50
Show Gist options
  • Save nowiwr01w/820fa8c5048f57de69aae6790b46220d to your computer and use it in GitHub Desktop.
Save nowiwr01w/820fa8c5048f57de69aae6790b46220d to your computer and use it in GitHub Desktop.
Simple API with Flask (local)
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