How to handle request requests in Finatra?

I have a service that has an endpoint. I want to have access to the url parameter as well as the body. How to achieve this.

This is my end point:

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

How do I access customerNum?

+4
source share
2 answers

Here you can extract things related to 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
source
put( / string) { (customerNumber: String) =>
    s"$customerNumber!"
  }
+1
source

Source: https://habr.com/ru/post/1687441/


All Articles