Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Building a Simple REST API | Python Fundamentals lesson | BraveProgrammer
  1. Courses
  2. /
  3. Python Fundamentals

Lesson 47 of 55

·Python

Building a Simple REST API

20 minutes

Course progress85%

What you'll learn

Keep these ideas in mind as you work through the lesson.

4 points
  • Return JSON with `jsonify()`.
  • Separate API routes from HTML view routes.
  • Use HTTP methods (`GET`, `POST`, `PUT`, `DELETE`) to build CRUD APIs.
  • For larger APIs, consider Flask‑RESTful or Flask‑RESTX.

Building a Simple REST API

Flask can also serve JSON APIs. Below we expose a /api/users endpoint that returns a list of user objects.

from flask import Flask, jsonify

app = Flask(__name__)

users = [
    {'id': 1, 'name': 'Alice'},
    {'id': 2, 'name': 'Bob'}
]

@app.route('/api/users')
def get_users():
    return jsonify(users)

if __name__ == '__main__':
    app.run(debug=True)

Visit 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.

Make it stickPractice what you've learned1 quiz · 5 practical tests · Optional activities from Python FundamentalsBrowse activities
Previous lessonIntroduction to Flask Web FrameworkContinue to lesson 48Database Access with SQLiteBack to Python Fundamentals curriculum