Ich habe eine POST-Spray-Route und die Anfrage enthält einen JSON-Body (Content-Type "application/json"). Ich möchte einen Weg, den rohen JSON aus dieser Anfrage in meiner Route zu extrahieren.Roh-JSON als String in einer Spray-POST-Route extrahieren
Für http://host:port/somepath/value1 möchte ich extrahieren der Postkörper als TextMsgResponse
. Aber für http://host:port/somepath/value2 Ich möchte Extrakt der Post Körper nur als Ausgangs Json (zB { "name":"Jack", "age":30 }
val myRoute = path("somepath"/Segment) { pathSegment =>
post { //use only POST requests
pathSegment match {
case "value1" =>
entity(as[TextMsgResponse]) { textMsg =>
complete {
//do something with the request
StatusCodes.OK
}
}
case "value2" => {
//here is I want to extract the RAW JSON from the request
}
}
}
Haben Sie versucht, 'Entität (wie [Array [Byte]]) 'oder' Entity (als [String]) '? – cmbaxter
Ja und beide funktionieren nicht. –