Skip to content

Commit

Permalink
feat: add query param on http RequestBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-alfers committed Jan 15, 2025
1 parent de0f354 commit 4e9d4d4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -36,6 +37,10 @@ public interface RequestBuilder<R> {

RequestBuilder<R> withTimeout(Duration timeout);

RequestBuilder<R> withQuery(String key, String value);

RequestBuilder<R> withQuery(Query query);

/**
* Transform the request before sending it. This method allows for extra request configuration.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
}
}

0 comments on commit 4e9d4d4

Please sign in to comment.