Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle put requests in Finatra?

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 ?

like image 960
deep Avatar asked Oct 13 '17 12:10

deep


1 Answers

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
    }
like image 163
Artavazd Balayan Avatar answered Nov 15 '22 07:11

Artavazd Balayan