我正在建立一个使用MERN Stack的图书馆管理系统,其中ISBN号是从免费的Google Book API中提取的。但我对如何获取应用程序的API感到困惑。
您可以使用浏览器实现的Fetch
API或与ReactJS一起使用的Ajax
(或任何前端代码)
通过NodeJS
,您可以以类似的方式使用request、request-promise、node-fetch、axios
等包。
使用NodeJS
可用的Request
库的示例
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'))