com.lightbend.lagom.scaladsl.server
Convenience function for creating Play service calls.
Convenience function for creating Play service calls.
def myServiceCall = PlayServiceCall { wrapCall =>
EssentialAction { requestHeader =>
// Wrap call can be invoked to get the action that will handle the call. It doesn't have to be
// invoked, a check could be done for example that would short circuit its invocation.
val wrappedAction = wrapCall(ServiceCall { request =>
println(s"Service call invoked with $request")
createSomeResponse()
}
// This will get the accumulator to consume the body. The accumulator wraps an Akka streams Sink. // Working with this gives you an opportunity to modify the incoming stream in whatever way you want, // before it's passed to the Lagom deserializer to deserialize it. accumulator: Accumulator[ByteString, Result] = wrappedAction(requestHeader)
accumulator.map { result =>
// At this point, the service call we invoked earlier has been invoked, and we now have the Play
// result that it has been converted to. We can modify this result as much as we want, including
// the body it is associated with.
result
}
}
}