I am building a server using Flask that will be called by a web client.
When a certain change occurs on the db my Flask app interacts with, I need the web client to be alerted so it can display the update.
Would someone be able to give me some direction as to what I should be looking into with regards to both the Flask and web client sides?
Thanks.
The terminology you are using is a little confusing. I'm going to assume the web client is someone visiting your Flask app over the internet.
Basically, if you want the ability for the server to push updates to the client you need to use websockets
http://en.wikipedia.org/wiki/WebSocket
Related
Is there a way that I could redirect every http get request coming to server to flask application and if certain condition is satisfied the app would pass request on but if not the app would block access to requested url.
The request coming from client to server is not related to flask app but I want to filter all requests and give permission only to those who met certain condition.
I would lite to try this in flask, but I am open to every solution possible.
I personally think Flask is a great option to handle a proxy server.
I currently don't have a straight solution as I never did it before but this is what I found around that seems legit (and will implement myself in the feature).
MOST SIMPLE ONE
By #ziozzang in Github
Flask Dance package
Proxies and HTTPS
Stack Overflow
By #AArias
Other
Using NGINX-reverse proxy with Flask and Docker
By #stewartadam in github
Making a flask proxy server, online, in 10 lines of code.
How To Create A Flask Proxy
flask-behind-proxy 0.1.1
I’m currently trying to serve multiple bots (running different models) and to allow users to interact with it on a website. I’ve had a look at the following: http://www.rasa.com/docs/nlu/http/, http://www.rasa.com/docs/core/http/ and http://www.rasa.com/docs/nlu/python/, but I’m still having trouble figuring out how it can be done.
Some of the solutions I’ve considered are either:
Serve the bot on a HTTP server and have my website interact with the Rasa HTTP server
Create the website on Django Framework or REST API, and run Rasa Core and NLU on the backend.
What would be the best way to go about doing this? And, could anyone please briefly explain how this can be done (with multiple bot models and instances running)?
Any help would be greatly appreciated!
For anyone else searching for an answer, I ended up using Flask as the server, along with Flask-SocketIO for real time communication. The server serves an API which allows clients to communicate with it via SocketIO, determines which bot to interact with, gets the response, and sends it back to the client.
I'm learning about basic back-end and server mechanics and how to connect it with the front end of an app. More specifically, I want to create a React Native app and connect it to a database using Python(simply because Python is easy to write and fast). From my research I've determined I'll need to make an API that communicates via HTTP with the server, then use the API with React Native. I'm still confused as to how the API works and how I can integrate it into my React Native front-end, or any front-end that's not Python-based for that matter.
I think you have to follow some online tutorial
And from my experiences, I think Flask is good choice for such case.
This is basic flask tutorial provided by tutorialspoint.com
You have to create a flask proxy, generate JSON endpoints then use fetch or axios to display this data in your react native app. You also have to be more specific next time.
Background
I am trying to create a simple REST API using the Flask-RESTful extension. This API will be working primarily to manage the CRUD and authentication of users for a simple service.
I am also trying to create a few web sockets using the Flask-SocketIO extension that these users will be able to connect to and see real-time updates for some data related to other people using the service. As such, I need to know that these users are authenticated and authorized to connect to certain sockets.
Problem
However, I'm having a bit of trouble getting set up. It seems like I am not able to have these two components (the REST API and SocketIO server) work together on the same Flask instance. The reason I say this is because when I run the following, either the REST API or the 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)
# some test resources for the API and
# a test emitter statement for the SocketIO server
# are added here
if __name__ == '__main__':
app.run(port=5000)
socketio.run(app, port=5005)
Question
Is the typical solution for this type of setup to have two distinct instances of Flask going at the same time? For instance, would my SocketIO server have to make requests to my REST API in order to check to see that a specific user is authenticated/authorized to connect to a specific socket?
You just want to run socketio.run(app, port=5005) and hit the REST API on port 5005.
The reason this works is because under the hood, Flask-SocketIO is running an evented webserver based on gevent (or with the 1.0 release, also eventlet) - this server handling the websocket requests directly (using the handlers you register via the socketio.on decorator) and is passing on the non-websocket requests to Flask.
The reason your code wasn't working is because both app.run and socketio.run are blocking operations. Whichever one ran first was looping, waiting for connections, never allowing the second to kick off. If you really needed to run your websocket connections on a different port you'd need to spawn either the socketio or the app run call on a different process.
Let's say I have a Flask app running. When someone goes to any page, or makes any sort of request on the page, I want that request to be copied to another Flask app. Is there an already existing Flask plugin that would allow me to do so?
By copy I mean this:
My app is test.com. I have another Flask app running on a private machine on a private IP. When I get a GET request on test.com, I want the same GET request to be sent to the Flask app on the private app.
As others have said in the comments, the best kind of proxy is that provided by your web server. However sometimes you actually need your web application to do the proxying, in that case see this answer: Proxying to another web service with Flask