Ho una route POST Spray e la richiesta contiene un corpo JSON (tipo di contenuto "application/json"). Voglio un modo per estrarre il JSON non elaborato da questa richiesta all'interno del mio percorso.Estrazione di JSON non elaborato come stringa all'interno di una route POST Spray
Per http://host:port/somepath/value1 voglio estratto il corpo posto di TextMsgResponse
. Ma per http://host:port/somepath/value2 voglio estratto il corpo dopo solo come JSON grezzo (ad esempio, { "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
}
}
}
Hai provato 'entità (come [Array [Byte]]) 'o' entity (as [String]) '? – cmbaxter
Sì ed entrambi non funzionano. –