2017-10-13 8 views
4

私は、エンドポイントを持つサービスを持っています。私は、url paramとbodyの両方にアクセスできるようにしたい。 これをどのように達成するのですか?Finatraにputリクエストを処理する方法は?

これは私のエンドポイントである:

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

私はcustomerNumにアクセスするにはどうすればよいですか?あなたはrequestに関連するものを抽出することができますどのようにここで

答えて

1
put(/ string) { (customerNumber: String) => 
    s"$customerNumber!" 
    } 
+0

私は「foo」というオブジェクトにアクセスすることはできませんこの方法です。私はfooオブジェクトとurlパラメータの両方が必要です – deep

2

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 
    } 
関連する問題