node.js - 阅读 API 文档
问题描述
我正在尝试重新创建这个创建一个新的卡API,但是基于文档,我不确定我应该如何传递所需的数据,它是否应该在查询参数中(req.params 来收集数据),例如
/1/cards?name=cardName&desc=cardDescription
,还是应该在 req.body 内?
解决方案
该文档显示了该 API 的大量示例。 其中一个示例甚至是为 nodejs 编写的。看起来很清楚,选项是查询参数,请求本身没有正文数据。
// This code sample uses the 'node-fetch' library:
// https://www.npmjs.com/package/node-fetch
const fetch = require('node-fetch');
fetch('https://api.trello.com/1/cards?idList=5abbe4b7ddc1b351ef961414', {
method: 'POST',
headers: {
'Accept': 'application/json'
}
})
.then(response => {
console.log(
`Response: ${response.status} ${response.statusText}`
);
return response.text();
})
.then(text => console.log(text))
.catch(err => console.error(err));
同样,CURL 示例也清楚地说明了这一点:
curl --request POST \
--url 'https://api.trello.com/1/cards?idList=5abbe4b7ddc1b351ef961414' \
--header 'Accept: application/json'
推荐阅读
- android - 打开软键盘时是否可以获得事件?
- node.js - Mongoose 是否与预配置吞吐量的 Cosmos DB 一起使用?
- amazon-web-services - SQS 消息接收器中缺少 MessageAttributes 属性
- python - 如何优化 3 个单独数组上的三重嵌套 for 循环(Python)
- javascript - 加载页面后,如何在我的 c# 程序中恢复通过 cefSharp 调用的 javascript 函数发送的列表?
- javascript - 如何将 props.theme.breakpoints 与 makeStyles 挂钩使用?
- latex - APA6 一位作者乳胶引用不起作用
- swiftui - 如何增加 SwiftUI 选择器中显示的最大行数?
- optimization - Adobe 分析与 adobe 目标的集成
- python - 尝试通过列表传递for循环时出现索引超出范围错误