gpt4 book ai didi

node.js - 如何从 MERN 堆栈 Web 应用程序项目中的 API 获取数据?

转载 作者:太空宇宙 更新时间:2023-11-03 23:59:39 25 4
gpt4 key购买 nike

我正在使用 MERN Stack 构建一个图书馆管理系统,其中 ISBN 编号是从免费的 Google Book API 中获取的。但我对如何获取 API 到我的应用程序感到困惑。

最佳答案

您可以使用fetch由浏览器或AJAX实现的API用于与 ReactJS(或任何与此相关的前端代码)一起使用

通过 nodejs,您可以以类似的方式使用 request、request-promise、node-fetch、axios 等包。

使用可用于 nodejsrequest 库的示例

request
.get('http://google.com/img.png' // api url)
.on('response', function(response) {
console.log(response.statusCode) // 200
console.log(response.headers['content-type']) // 'image/png'
// save the image somewhere, or render to webpage
})
.pipe(request.put('http://yoursite.com/img.png'))

关于node.js - 如何从 MERN 堆栈 Web 应用程序项目中的 API 获取数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55373973/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com