Pure Flask exampleΒΆ

In this example, we are exposing 4 endpoints in the server. An index endpoint, 2 authentication endpoints, and a user profile endpoint. We are also using the jwt_required decorator provided by the Flask-JWT-Extended extension to simulate the authentication process. This is a very classic example of REST APIs implemented with Flask. Checkout Flask-Mux example to learn how to integrate Flask-Mux with this app to make it more modular.

from flask import Flask
from flask_jwt_extended import (

app = Flask(__name__)
jwt = JWTManager(app)

def home():
    return 'home page'

@app.route('/auth/login', methods=['POST'])
def login():
    identity = {'user_id': 1234}
    return { 'access_token': create_access_token(identity) }

@app.route('/auth/logout', methods=['POST'])
def logout():
    return { 'message': 'logged out' }

def profile(id):
    return { 'user': id }