gpt4 book ai didi

rest - 如何在 sails 的 action2 中获取查询参数

转载 作者:可可西里 更新时间:2023-11-01 16:31:56 28 4
gpt4 key购买 nike

我不知道如何根据 REST 为这样的搜索请求 url 设置路由

localhost:1337/system?id=10

之后,我们如何才能像这样在action 2中从上面的请求中获取参数

action2(inputs,exits)

我想遵循 sails 中 web api 的最佳实践。请提示我解决并推荐任何方便的文件。提前致谢

最佳答案

对于 Actions2 格式,您当然会在正确定义输入后使用 inputs.id。有关更多信息,请咨询 documentation on Actions and Controllers .这需要更多的整理,但它会得到您的输入和一个功能。您可能想要添加退出,当然还有一些真实的逻辑,可能还有一些体面的描述。

module.exports = {
inputs: {
id: {
type: 'number',
required: true
}
},
exits: {
success: { ... },
error: { ... }
},
fn: async function (inputs, exits) {
var myId = inputs.id;
return exits.success(myId);
}
}

关于rest - 如何在 sails 的 action2 中获取查询参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50696569/

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