I need a request module that works both in the Node.js server and in the client, when bundled with Webpack.
当与Webpack捆绑在一起时,我需要一个在Node.js服务器和客户端都可以工作的请求模块。
My requirements are really basic. I just need to do some HTTP Ajax requests, like get
and post
. Automatic JSON parsing would be awesome.
我的要求非常基本。我只需要做一些HTTP Ajax请求,比如get和post。自动JSON解析会很棒。
I'm taking a look at Request, which seems solid by the number of commits and downloads, but the website doesn't mention whether it works while bundled in the browser.
我正在看一下Request,它看起来很可靠,但是提交和下载的数量似乎很稳定,但网站没有提到它是否在浏览器中捆绑时有效。
Any suggestion?
2 个解决方案
#1
4
I use axios
我用的是axios
Promise based HTTP client for the browser and node.js
基于Promise的HTTP客户端,用于浏览器和node.js
Features
- Make XMLHttpRequests from the browser
- Make http requests from node.js
- Supports the Promise API
- Intercept request and response
- Transform request and response data
- Cancel requests
- Automatic transforms for JSON data
- Client side support for protecting against XSRF
从浏览器生成XMLHttpRequests
从node.js发出http请求
支持Promise API
拦截请求和响应
转换请求和响应数据
自动转换JSON数据
客户端支持防范XSRF
#2
2
Try SuperAgent
SuperAgent is a small progressive client-side HTTP request library, and Node.js module with the same API
SuperAgent是一个小型渐进式客户端HTTP请求库,Node.js模块具有相同的API
Works with browserify and should work with webpack
与browserify一起使用,应该与webpack一起使用
#1
4
I use axios
我用的是axios
Promise based HTTP client for the browser and node.js
基于Promise的HTTP客户端,用于浏览器和node.js
Features
- Make XMLHttpRequests from the browser
- Make http requests from node.js
- Supports the Promise API
- Intercept request and response
- Transform request and response data
- Cancel requests
- Automatic transforms for JSON data
- Client side support for protecting against XSRF
从浏览器生成XMLHttpRequests
从node.js发出http请求
支持Promise API
拦截请求和响应
转换请求和响应数据
自动转换JSON数据
客户端支持防范XSRF
#2
2
Try SuperAgent
SuperAgent is a small progressive client-side HTTP request library, and Node.js module with the same API
SuperAgent是一个小型渐进式客户端HTTP请求库,Node.js模块具有相同的API
Works with browserify and should work with webpack
与browserify一起使用,应该与webpack一起使用