【问题标题】:How to return non 200 HTTP status codes with Serverless + OpenWhisk and behind IBM Cloud API Gateway?如何使用 Serverless + OpenWhisk 和 IBM Cloud API Gateway 返回非 200 HTTP 状态代码?
【发布时间】:2019-02-04 00:21:42
【问题描述】:

我不知道如何为 API GW 后面的函数返回 http 状态代码。无论我返回什么,它总是以 200 的形式返回。我试过 statusCodecode 无济于事。

我正在使用带有 OpenWhisk 插件的无服务器框架。我正在部署到 IBM Cloud。

【问题讨论】:

  • 你的函数必须返回一个像{ statusCode: 200, headers: { 'Content-Type': 'application/json' }, body: {} }这样的格式化响应你能分享你的代码吗?这些文档可能会有所帮助github.com/apache/incubator-openwhisk/blob/master/docs/…
  • statusCode 应该可以解决问题,查看@user6062970 为 webactions 共享的文档

标签: openwhisk


【解决方案1】:

Web 操作响应内容类型参数必须设置为 http 才能手动设置为 configure the HTTP response。此值默认为json,它忽略返回的headersstatusCode 值。

在无服务器框架中,此值设置在 YAML 的 event configuration section 中。

functions:
  my_function:
    handler: index.main
    events:
      - http:
          method: GET
          path: /api/greeting
          resp: http

【讨论】:

    猜你喜欢
    • 2016-01-27
    • 2014-02-08
    • 2018-05-19
    • 2011-07-01
    • 2017-06-27
    • 2017-01-28
    • 2015-09-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多