I'm POCing pekko http ( akka http ) for my next project. I extracted json string from request body entity but it doesn't have quote on string value.
Code snippet on route dsl :
post {
path("account") {
extract(_.request) { request =>
val body = Await.result(request.entity.toStrict(1.second).map(_.data.utf8String), 1.second)
println(body)
complete(...)
}
}
}
request : curl -X POST http://localhost:9090/account -d '{"account":{"name":"TESTE"}}'
extracted json string : {account:{name:TESTE}}
Anybody know how to extract request body entity without removing quotes ?
There is nothing stopping you to do it this way, however blocking with Await is not a good practice when using akka-http. This also extracts the raw JSON string without removing the quotes:
Working example: https://github.com/pbernet/akka_streams_tutorial/blob/70e52e6e769a2779f1a6de744aab3cf4f16a3835/src/main/scala/akkahttp/SampleRoutes.scala#L121
To inspect the request on the server you may set these parameters in the application.conf in order to detect env issues.