deep
deep

Reputation: 1676

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 ?

Upvotes: 5

Views: 258

Answers (2)

Artavazd Balayan
Artavazd Balayan

Reputation: 2413

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
    }

Upvotes: 4

aravindKrishna
aravindKrishna

Reputation: 440

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

Upvotes: 1

Related Questions