如何在Finatra中处理put请求?

时间:2017-10-13 12:11:07

标签: scala finagle twitter-finagle finatra

我有一个具有put端点的服务。我希望能够访问url param以及body。 我如何实现这一目标。

这是我的终点:

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

如何访问customerNum?

2 个答案:

答案 0 :(得分:4)

在此处您可以提取与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
    }

答案 1 :(得分:1)

put( / string) { (customerNumber: String) =>
    s"$customerNumber!"
  }
相关问题