File: flask-sever.py
This is the main Flask server code that will be listening on the port 5000
.
File: express-sever.js
This is the main code for your Express server, running on port 5600
.
The WebSocket code on port 5800
has been included in the same File for ease of understanding. However, it is recommended to separate these functionalities into separate Files in the future.
Files: index.html
and page2.html
These are the HTML Files that are rendered by Flask.
index.html
: This is the home page HTML File which contains a title and a subtitle. It also includes a JavaScript script, index.js, located in the Scripts folder, which handles WebSocket.page2.html
: This is the HTML File of page 2 that displays information received as parameters.
File: index.js
This is the JavaScript File for the index.html
page that runs on the client to handle the WebSocket and redirection to page2.html
.
File: flask-to-express.py This is the Python code to make a POST request to the Express server
We define a route to the home page that renders the index.html
template.
We define a route that returns a JSON containing employee information.
We define a route that takes an age
parameter and returns employees older than the given value.
We define a route that takes name
and age
parameters and returns the employees with the corresponding information.
We define a route that receives data via POST and prints the information on the server. The route returns a JSON response.
We define a route that renders page2.html
, passing information as parameters.
- Clone this repository with the following command:
git clone
- Start the
Flask
server
python flask-sever.py
- Start the
Express
server
node express-sever.js
- Make the posts,
POST
, on both servers:
python flask-to-express.py