简体   繁体   English

如何使用 React 前端和 Flask 后端处理 HTTP 请求

[英]How can I handle HTTP request with react front-end and flask back-end

I am building a web application using flask framework for my back-end and my front-end in react.我正在使用 Flask 框架为后端和前端构建一个 Web 应用程序。 I would like to connect these two using http request but I have no clue on where to start.我想使用http请求连接这两个,但我不知道从哪里开始。 I am using PyCharm IDE for both front and back end.我在前端和后端都使用PyCharm IDE

I have looked into react-http-request library but I didn't understand it.我查看了react-http-request库,但我不明白。

I want to be able to send strings from my front-end to my back-end and send json files from back-end to front-end.我希望能够将字符串从前端发送到后端,并将json文件从后端发送到前端。

Native fetch() function of the browser can do that for you.浏览器的本机 fetch() 函数可以为您做到这一点。

Use it like this:像这样使用它:

fetch('http://your.server.domain/api/endpoint', {
  method: 'GET',
  headers: {"Content-Type": "application/json"},
}).then((res) => {
  return res.json();
}).then((json) => {
  // this is your json data from your server
  console.log(json);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在服务器上部署Node Js后端和React Js前端? - How can I deploy Node Js back-end and React Js front-end on server? 无法从 React 前端向 Node.js 后端发送 POST 请求 - Can't send POST request from React front-end to Node.js back-end 如何从反应前端向节点后端发出发布请求? 获得 404 - How do I make a post request from a react front-end to a node back-end? Getting 404 如何同时运行我的前端反应和后端反应? - How do I run my react front-end and express back-end together? React 前端和 Node 后端的安全性 - Security for React front-end and Node back-end 我应该在后端还是前端实现getStream? - Should I implement getStream on Back-End or Front-End? 我应该分别测试前端和后端吗 - Should I test front-end and back-end separately 连接前端和后端 - connecting front-end to back-end 我应该在后端(Rails API)还是前端(React/Redux)上查询和过滤 - Should I query and filter on the back-end (Rails API) or front-end (React/Redux) 在我的情况下,我应该如何使用 OAuth 2.0 授权授予(反应前端,Spring 引导后端) - How should I use the OAuth 2.0 Authorization grant in my case (React front-end, Spring Boot back-end)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM