Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

50 - Flask REST API with Auth

Python Difficulty: Expert Phase

What It Does

A Flask-based REST API with JWT authentication, user registration, login, and protected endpoints.

Run It

pip install -r requirements.txt
python app.py

Core Concepts

  • Flask application factory pattern
  • JWT token generation and validation
  • Password hashing with werkzeug
  • Protected routes with auth decorators
  • RESTful endpoint design

What You Will Learn

You will learn how to build authenticated REST APIs with JWT token flows and security best practices.

Project Structure

50-flask-rest-api/
  README.md
  app.py
  requirements.txt

Prerequisites

Install the required packages before running:

pip install flask

Example Output

Flask REST API
--------------
 * Running on http://127.0.0.1:5000

Endpoints:
  POST /register  - Register new user
  POST /login     - Get JWT token
  GET  /protected - Access protected resource (requires token)
  GET  /users     - List all users (admin only)

Example:
  curl -X POST /login -d '{"username":"admin","password":"secret"}'
  -> {"token": "eyJhbGciOi..."}