I have several components that proxy requests to a REST service and deserializes the result as appropriate. For example, something like:
import akka.http.scaladsl.HttpExt
trait UsersResource {
val http: HttpExt
def getUser(id: String): Future[User] = http.singleRequest(HttpRequest(...))
.flatMap(r => Unmarshal(r.entity).to[User])
def findUsers(query: Any): Future[List[User]]
}
I'd like to somehow proxy each of these requests, so that I can modify the request (eg. to add headers) or modify the response. Specifically, I'm interested in adding some code that adds:
- logging and monitoring request/response
- add cookies to each request
- add auth to request
- transform the response body
Since each specific resource typically has these three steps in common (and in some cases this logic is common across all resources), I'd like to change the http: HttpExt
field somehow to apply these steps.
Is anything like this possible with Akka HTTP?
I came across this question, which seems to touch on part of this question (specifically the part about logging/monitoring) however the accepted answer appears to be using HTTP Directives on the server side, rather than at the client.