Class ReactiveRequest


  • public class ReactiveRequest
    extends Object

    A reactive wrapper over Jetty's HttpClient Request.

    A ReactiveRequest can be obtained via a builder:

     // Built with HttpClient and a string URI.
     ReactiveRequest request = ReactiveRequest.newBuilder(httpClient, uri()).build();
    
     // Built by wrapping a Request.
     Request req = httpClient.newRequest(...);
     ...
     ReactiveRequest request = ReactiveRequest.newBuilder(req).build();
     

    Once created, a ReactiveRequest can be sent to obtain a Publisher for a ReactiveResponse passing a function that handles the response content:

     Publisher<T> response = request.response((response, content) -> { ... });
     
    • Constructor Detail

      • ReactiveRequest

        protected ReactiveRequest​(org.eclipse.jetty.client.api.Request request)
    • Method Detail

      • newBuilder

        public static ReactiveRequest.Builder newBuilder​(org.eclipse.jetty.client.HttpClient httpClient,
                                                         String uri)
        Parameters:
        httpClient - the HttpClient instance
        uri - the target URI for the request - must be properly encoded already
        Returns:
        a builder for a GET request for the given URI
      • newBuilder

        public static ReactiveRequest.Builder newBuilder​(org.eclipse.jetty.client.api.Request request)
        Parameters:
        request - the request instance
        Returns:
        a builder for the given Request
      • getReactiveResponse

        public ReactiveResponse getReactiveResponse()
        Returns:
        the ReactiveResponse correspondent to this request, or null if the response is not available yet
      • getRequest

        public org.eclipse.jetty.client.api.Request getRequest()
        Returns:
        the wrapped Jetty request
      • response

        public org.reactivestreams.Publisher<ReactiveResponse> response()

        Creates a Publisher that sends the request when a Subscriber requests the response via Subscription.request(long), discarding the response content.

        Returns:
        a Publisher for the response
      • response

        public <T> org.reactivestreams.Publisher<T> response​(BiFunction<ReactiveResponse,org.reactivestreams.Publisher<ContentChunk>,org.reactivestreams.Publisher<T>> contentFn)

        Creates a Publisher that sends the request when a Subscriber requests the response via Subscription.request(long), processing the response content with the given function.

        Type Parameters:
        T - the element type of the processed response content
        Parameters:
        contentFn - the function that processes the response content
        Returns:
        a Publisher for the processed content
      • requestEvents

        public org.reactivestreams.Publisher<ReactiveRequest.Event> requestEvents()
        Returns:
        a Publisher for request events