Lesson 47 of 55 · Python
Building a Simple REST API
Duration: 20 minutes
Lesson 47 of 55 · Python
Duration: 20 minutes
/api/users endpoint that returns a list of user objects.\n\npython\nfrom flask import Flask, jsonify\n\napp = Flask(__name__)\n\nusers = [\n {'id': 1, 'name': 'Alice'},\n {'id': 2, 'name': 'Bob'}\n]\n\n@app.route('/api/users')\ndef get_users():\n return jsonify(users)\n\nif __name__ == '__main__':\n app.run(debug=True)\n\n\nVisit http://127.0.0.1:5000/api/users to see the JSON response. You can extend the API with POST, PUT, and DELETE methods for full CRUD support.\n