Configuring the React frontend for API consumption
In this section, you will configure the frontend React app to communicate with the backend Flask server by setting up a proxy in React to consume the API from the Flask server.
In order to configure the React proxy for API consumption, you will need to update the proxy
field in the package.json
file of the frontend React app. The proxy
field allows you to specify a URL that will be used as the base for all API requests made from the React app.
Let’s update the package.json
file:
- Open the
package.json
file in theproject
directory using a text editor, and then add aproxy
field to thepackage.json
file and set it to the URL of your Flask server:{ "name": "bizza", "version": "0.1.0", "proxy": "http://localhost:5000"}
- Next, you will need to make HTTP requests to the Flask server from the React frontend. We will use the...