How to handle put requests in Finatra?

249 Views Asked by At

I have a service which has a put endpoint. I want to be able to access the url param as well as the body. How do I achieve this.

This is my endpoint:

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

How do I access customerNum ?

2

There are 2 best solutions below

0
Artavazd Balayan On BEST ANSWER

Here how 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
    }
1
aravindKrishna On
put( / string) { (customerNumber: String) =>
    s"$customerNumber!"
  }