Get http headers with akka routing dsl

I’m new to Scala, and this problem frustrates me. How can I get all headers from request? val route = { path(“lol”) { //get httpHeaders complete(HttpResponse()) } } Answer You have at least two options here: a) Using extractRequest directive: val route = { path(“example”) { extractRequest { request => request.headers // Returns `Seq[HttpHeader]`; do … Read more

How to properly call Akka HTTP client for multiple (10k – 100k) requests?

I’m trying to write a tool for batch data upload using Akka HTTP 2.0-M2. But I’m facing akka.stream.OverflowStrategy$Fail$BufferOverflowException: Exceeded configured max-open-requests value of [32] error. I tried to isolate a problem and here is the sample code which also fails: public class TestMaxRequests { private static final class Router extends HttpApp { @Override public Route … Read more

How can I use a Future inside an Akka HTTP Directive?

I currently have a directive that I’m using to secure resources in an Akka HTTP app, like so: def authenticate: Directive1[Login] = optionalHeaderValueByName(“Authorization”) flatMap { val accessToken = authz.split(‘ ‘).last case Some(authz) => LoggedInUser findByAccessToken accessToken match { case Some(user) => provide(user) case None => reject(AuthorizationFailedRejection) } case None => reject(AuthorizationFailedRejection) } where LoggedInUser.findByAccessToken() makes … Read more

Correct use of Akka http client connection pools

I need to consume a REST service using Akka’s HTTP client (v2.0.2). The logical approach is to do this via a host connection pool because we expect large numbers of simultaneous connections. The Flow for this consumes a (HttpRequest, T) and returns a (Try[HttpResponse, T). The documentation indicates that some arbitrary type T is needed … Read more