diff --git a/akka-javasdk/src/main/java/akka/javasdk/http/RequestBuilder.java b/akka-javasdk/src/main/java/akka/javasdk/http/RequestBuilder.java index 4066a6126..c07e62754 100644 --- a/akka-javasdk/src/main/java/akka/javasdk/http/RequestBuilder.java +++ b/akka-javasdk/src/main/java/akka/javasdk/http/RequestBuilder.java @@ -9,6 +9,7 @@ import akka.http.javadsl.model.HttpHeader; import akka.http.javadsl.model.HttpRequest; import akka.http.javadsl.model.headers.HttpCredentials; +import akka.http.javadsl.model.Query; import java.time.Duration; import java.util.concurrent.CompletionStage; @@ -36,6 +37,10 @@ public interface RequestBuilder { RequestBuilder withTimeout(Duration timeout); + RequestBuilder withQuery(String key, String value); + + RequestBuilder withQuery(Query query); + /** * Transform the request before sending it. This method allows for extra request configuration. */ diff --git a/akka-javasdk/src/main/scala/akka/javasdk/impl/http/HttpClientImpl.scala b/akka-javasdk/src/main/scala/akka/javasdk/impl/http/HttpClientImpl.scala index 2aece370b..eb11b1e8b 100644 --- a/akka-javasdk/src/main/scala/akka/javasdk/impl/http/HttpClientImpl.scala +++ b/akka-javasdk/src/main/scala/akka/javasdk/impl/http/HttpClientImpl.scala @@ -17,6 +17,8 @@ import akka.http.javadsl.model.HttpMethods import akka.http.javadsl.model.HttpRequest import akka.http.javadsl.model.HttpResponse import akka.http.javadsl.model.headers.HttpCredentials +import akka.http.javadsl.model.Query +import akka.japi.Pair import akka.javasdk.JsonSupport import akka.javasdk.http.HttpClient import akka.javasdk.http.RequestBuilder @@ -192,4 +194,12 @@ private[akka] final case class RequestBuilderImpl[R]( timeout, request, (res: HttpResponse, bytes: ByteString) => new StrictResponse[T](res, parse.apply(bytes.toArray))) + + override def withQuery(key: String, value: String): RequestBuilder[R] = withQuery( + Query.create(Pair.create(key, value))) + + override def withQuery(query: Query): RequestBuilder[R] = { + val uriWithQuery = request.getUri.query(query) + withRequest(request.withUri(uriWithQuery)) + } }