javascript - 尝试删除 id 数组时,删除请求 api 在控制台中显示错误
问题描述
我试图通过实现一个带有查询参数的处理程序来删除一个 id 数组。我之前实现了一个删除 api 函数,它接受一个 id 并将其删除。但是,现在我创建了一个新端点,它将清除整个数组。新端点是:
上面端点中的 id 只是虚拟的,用于向您展示它应该如何获取 id。
configIds 作为查询参数传递,响应将是这样的:
所以我所做的是将新端点添加到现有的删除 api 函数中,该函数当前需要一个 configId。所以:
async function deleteConfig(configId) {
const options = {
method: 'DELETE',
headers: {
'content-type': 'application/json'
},
url: configId.includes(',') ? `/api/v1/algo/configs?configIds=${configId}` : `${ALGOS_API_ROOT}/configs/${configId}`
};
return axios(options);
但是,我在这里遇到错误:
api/v1/private/api/v1/algo/configs?configIds=41,40,38,23,22 404 (Not Found)
如您所见,正在传递 id。但是有一个错误。任何帮助,将不胜感激。谢谢!
解决方案
在请求正文中发送 id 数组。
async function deleteConfig(configId) {
const options = {
method: 'DELETE',
headers: {
'content-type': 'application/json'
},
url: `${ALGOS_API_ROOT}/configs`,
data: {
ids: [1, 2, 3]
}
};
return axios(options);
}
推荐阅读
- github - travis-ci 中的工作服输出没有可用的报告文件,并且 repo 令牌为空
- heroku - 使用 Heroku 和 Amazon S3 上的 Active Storage 使用上传的 Roo gem 打开远程文件
- sql - 对象名称无效,但对象显然有效
- java - 如何为多个模块配置 Log4J2?
- .net - 这种时间格式有名称吗?
- scala - 如果对象中的某些字段相同,则对象的scala过滤器列表
- javascript - 是否所有 JavaScript Iterables 都有 next() 方法?
- ssl - Filebeat:由未知权威签署的证书
- h2 - Derby 的 H2 INIT 等效项
- r - 基于条件的滞后数据(非固定滞后)