I try to get the payload from a POST in Play 2.3.
Therefore I use this expression.
val name = request.body.asFormUrlEncoded.get("name").flatMap(_.headOption)
But I run into trouble, when the field "name" is not present. Using the debugger, I can see that request.body.asFormUrlEncoded is of type Some(Map) or ListMap? I'm not sure, in the debugger both terms are displayed. When the field "name" exists, everything is fine, but if the field "name" is missing, it throws an NoSuchElementException.
I can see that only calling request.body.asFormUrlEncoded.get("name") does return an ArrayBuffer. But shouldn't it return a Some(ArrayBuffer) and a None in case of "name" field is not existing?
So what can I do to query the value of a field without generating an exception if the field is missing.
Added: Here is the declaration of AnyContentAsFormUrlEncoded. So it's a Map. But get on a Map should return Some or None, but not directly the object.
case class AnyContentAsFormUrlEncoded(data: Map[String, Seq[String]]) extends AnyContent