2017-10-13 44 views
4

我有一個有put端點的服務。我希望能夠訪問url參數以及body。 我該如何做到這一點。如何處理Finatra中的請求?

這是我的終點:

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

如何訪問customerNum?

回答

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

這樣,我不會有機會獲得「foo」的對象。我想要foo對象和url參數 – deep

2

在這裏你可以如何提取與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 
    }