A Flask-based REST API with JWT authentication, user registration, login, and protected endpoints.
pip install -r requirements.txt
python app.py- Flask application factory pattern
- JWT token generation and validation
- Password hashing with werkzeug
- Protected routes with auth decorators
- RESTful endpoint design
You will learn how to build authenticated REST APIs with JWT token flows and security best practices.
50-flask-rest-api/
README.md
app.py
requirements.txt
Install the required packages before running:
pip install flaskFlask 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..."}