5

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 ?

deep
  • 1,586
  • 1
  • 18
  • 29

2 Answers2

4

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
    }
Artavazd Balayan
  • 2,353
  • 1
  • 16
  • 25
1
put( / string) { (customerNumber: String) =>
    s"$customerNumber!"
  }
aravindKrishna
  • 440
  • 2
  • 11
  • This way I won't have access to the "foo" object. I want both the foo object and the url parameter – deep Oct 13 '17 at 13:40