Background
I am trying to create a simple REST API using the Flask-RESTful extension. This API will work primarily for CRUD management and user authentication for a simple service.
I am also trying to create several web sockets using the Flask-SocketIO extension, with which these users can connect and view real-time updates for some data related to other people using this service. Thus, I need to know that these users are authenticated and authorized to connect to specific sockets.
Problem
However, I had problems with the setup. It seems like I cannot use these two components (REST API and SocketIO server) together in the same Flask instance. The reason I say this is because when I run the following, either a REST API or a SocketIO server will work, but not both:
from flask import Flask from flask_restful import Api from flask.ext.socketio import SocketIO app = Flask(__name__) api = Api(app) socketio = SocketIO(app)
Question
Is a typical solution for this type of installation to have two different Flask instances running at the same time? For example, should my SocketIO server make requests to my REST API to verify that a particular user is authenticated / authorized to connect to a specific socket?
source share