0

So here is my code:

post((name :: stringBody) :+: headerOption[String]("AMI-WS-Header")) { (body: String, amiHeader: String) =>
  val response: HttpResponse[String] = Http(url + name).headers(
    if (name == "login") Map("Content-Type" -> "application/json")
    else Map("Content-Type" -> "application/json", "AMI-WS-Header" -> amiHeader)
  ).postData(body).asString
  Ok(parse(response body).right.get)

As you can see, I'm trying to get a specific header along with the body of the request. However it gives me the following error:

Error:(32, 9) overloaded method value apply with alternatives:
  (input: io.finch.Input)io.finch.Endpoint.Result[String :+: Option[String] :+: shapeless.CNil] <and>
  (mapper: io.finch.syntax.Mapper[String :+: Option[String] :+: shapeless.CNil])io.finch.Endpoint[mapper.Out]
  cannot be applied to ((String, String) => io.finch.Output[io.circe.Json])
  post((name :: stringBody) :+: headerOption("AMI-WS-Header")) { (body: String, amiHeader: String) =>

I've searched a lot for a solution but haven't come across anything so far.

What is the right way to get a specific header value from the post request?

Adifyr
  • 2,649
  • 7
  • 41
  • 62
  • `post(name :: stringBody :: headerOption[String]) { (body: String, header: Option[String]) => ... } should work. – Vladimir Kostyukov Jun 28 '18 at 04:05
  • Yes, that was the issue. I was taking the wrong type. :) Thanks though! Would you like to add it as an answer so that I may mark it as correct? – Adifyr Jun 28 '18 at 07:32

0 Answers0