Almost the same as skornos, but with variable declarations for a more explicit answer. It can work with Flask-RESTful extension:
from flask import Flask
from flask_restful import Resource, Api
app = Flask(__name__)
api = Api(app)
class UserAPI(Resource):
def show(userId, username=None):
pass
api.add_resource(UserAPI, '/<userId>', '/<userId>/<username>', endpoint='user')
if __name__ == '__main__':
app.run()
The add_resource
method allows pass multiples URLs. Each one will be routed to your Resource.