【问题标题】:How to handle put requests in Finatra?如何处理 Finatra 中的 put 请求?
【发布时间】:2018-03-25 13:46:37
【问题描述】:

我有一个服务,它有一个 put 端点。我希望能够访问 url 参数以及正文。 我如何做到这一点。

这是我的终点:

put("/:customerNum") { foo: Foo =>
    val custNum = ???
  }

如何访问 customerNum ?

【问题讨论】:

    标签: scala finagle twitter-finagle finatra


    【解决方案1】:

    这里你可以如何提取与request相关的东西:

    put("/:customerNum") { request =>
          // Get request body
          val body = request.getContentString
          // Get content type
          val contentType = request.contentType
          // Get customer number
          val customerNum = request.routeParams.get("customerNum")
    
          println(s"Customer number: ${customerNum}. Content Type: $contentType. Body: $body")
          render.plain("ok").toFuture
        }
    

    【讨论】:

      【解决方案2】:
      put( / string) { (customerNumber: String) =>
          s"$customerNumber!"
        }
      

      【讨论】:

      • 这样我将无法访问“foo”对象。我想要 foo 对象和 url 参数
      猜你喜欢
      • 2013-09-06
      • 2014-08-26
      • 2017-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-21
      • 1970-01-01
      相关资源
      最近更新 更多