简体   繁体   English

Typescript / React前端+ Python后端Web服务

[英]Typescript/React front end + Python backend web service

If i have a simple python backend web service (microservice) using django or flask. 如果我有一个使用django或flask的简单python后端Web服务(微服务)。 It takes a request (POST or GET) in the form of JSON that will include 2 integer inputs: A, and B, it'll then perform A+B and return the result as an integer in a JSON HTTP response. 它以JSON形式接收一个请求(POST或GET),该请求将包含2个整数输入:A和B,然后执行A + B并将结果作为整数返回到JSON HTTP响应中。

And I plan to write a singe page web application using Typescript and React to access that service (send requests and getting the sum as responses) and display the results on my page. 而且我计划使用Typescript和React编写一个单页Web应用程序以访问该服务(发送请求并获取总和作为响应)并在页面上显示结果。 The SPA wll just have 2 text boxes for me to enter the 2 numbers, and it'll display the sum below as returned by the service when whenever I click 'submit'. SPA只会有2个文本框供我输入2个数字,每当我单击“提交”时,SPA就会在下方显示该服务返回的总和。

What do I need as far as my frontend is concerned (assuming backend is already running on the web). 就前端而言,我需要什么(假设后端已在网络上运行)。

Based on my understanding I need: 根据我的理解,我需要:

1) NPM (to install react) 1)NPM(要安装反应)

2) Node.js (to use NPM) 2)Node.js(使用NPM)

3) React framework (installed using NPM. Yes such a simple app probably won't need it but I'm just using this as an example for a true non-trivial frontend app later on.) 3)React框架(使用NPM安装。是的,这样一个简单的应用程序可能不需要它,但稍后我将以它为例,说明真正的平凡前端应用程序。)

4) Webpack (Same as react: I may not need this for this simple application, but in general why do I need it?) 4)Webpack(与react相同:对于这个简单的应用程序,我可能不需要它,但是总的来说,为什么我需要它?)

5) Babel (only if I need to make my typescript compatible with older browsers?) 5)Babel(仅当我需要使我的打字稿与旧版浏览器兼容时?)

6) Bootstrap (only if I want the SPA's look and feel to be standardized and fancy?) 6)Bootstrap(仅当我希望SPA的外观和风格标准化且花哨时?)

7) A modern browser like Chrome to display the SPA in. 7)像Chrome这样的现代浏览器可以显示SPA。

What else am I missing in terms of a modern frontend tech stack for this app? 在此应用程序的现代前端技术堆栈方面,我还缺少什么? IN particular, I'm curious as to the role Node.js will play here: it seems I only need node.js to use npm. 特别是,我对Node.js在这里扮演的角色感到好奇:看来我只需要node.js来使用npm。 Is that right? 那正确吗?

I would recommend using create-react-app, all you have to do is run 'npx create-react-app app-name' in a terminal and it will set up a react project, rename all .jsx files to .tsx and run 'npm start' It supports typescript automatically and will generate a config file for it when it detects you're using typescript. 我建议使用create-react-app,您所要做的就是在终端中运行“ npx create-react-app app-name”,它将建立一个react项目,将所有.jsx文件重命名为.tsx并运行'npm start'它自动支持打字稿,并在检测到您正在使用打字稿时为其生成配置文件。 It hides the webpack configuration and supports most common use cases out of the box. 它隐藏了webpack配置,并支持开箱即用的最常见用例。

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

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