2017-10-13 46 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 
    }