简体   繁体   中英

Why would Flask be used with Reactjs for Restful APIs?

I have heard of people who use Flask with Reactjs to build REST APIs. However, I am very confused by why Flask is needed when Reactjs can handle GET and POST requests .

To bring some context behind why this question is important for me: At work, we build web apps where a customer/user inputs some data (eg favourite food). This data is then processed using python libraries and scripts and then an output (eg recipe for the food) is returned to the user.

Why might Flask with React be better than React by itself?

React and flask are two separate solutions for different problems. In the context of a REST API, flask (on top of python) can be used to provide the API. React on the other hand is a client-side framework and is thus at best indirectly involved in consuming it.

Neither React nor flask is needed, both are independent convenience frameworks. React for the JavaScript client-side, flask for the Python server-side.

React makes it easier to provide an HTML interface to the user, flask makes it easier to reply to incoming HTTP requests on the server.

React is just a javascript library which helps in building user interfaces, whereas flask is a microframework for building web applications. Handling http requests in the context of React means that it can make http requests and make decisions based on what they output. React does not have control over the business logic ie the way the requests are going to get processed, which in your case is deciding recipe based on user's input. That's where flask or a backend comes into picture, it would take the input given by the frontend, do some processing and return some output. Over here http is just a medium of passing information from frontend to the backend.

To understand these concepts a bit more you could research more on the MVC architecture.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM