【问题标题】:Calling the same endpoint with multiple requests使用多个请求调用同一个端点
【发布时间】:2021-11-18 16:05:31
【问题描述】:

我正在弃用旧 API,并希望两个(或多个)请求调用同一个端点。像这样的:

@Get('/request')      // call endpoint with this request
@Get('/otherRequest') // or with this request
test() {
  // do something
}

显然,另一种方法是创建另一个端点并使用服务来共享功能,但我很好奇这是否可行,因为它会使流程更易于实施。

【问题讨论】:

    标签: api request nestjs endpoint


    【解决方案1】:
    @Get(['/request', '/otherRequest'])
    test() {
      // do something
    }
    

    tip:检查@Get()的TS类型^^

    【讨论】:

    • 哦,废话,我忘了这实际上是一件事!不是@Get(['request', 'otherRequest'])吗? string | string[]
    • 哈哈。我的错。固定的! ty
    • 这太棒了,谢谢
    猜你喜欢
    • 2021-10-31
    • 1970-01-01
    • 2022-11-30
    • 2021-06-27
    • 2018-11-01
    • 2021-10-14
    • 1970-01-01
    • 1970-01-01
    • 2023-03-12
    相关资源
    最近更新 更多