/// <summary>
        /// Set response caching options for the request.
        /// </summary>
        /// <param name="requestBuilder">Request builder instance.</param>
        /// <param name="configure">Action to configure options.</param>
        public static FluentHttpRequestBuilder WithResponseCachingOptions(this FluentHttpRequestBuilder requestBuilder, Action <ResponseCacheHttpMiddlewareOptions> configure)
        {
            var options = new ResponseCacheHttpMiddlewareOptions();

            configure?.Invoke(options);
            return(requestBuilder.WithResponseCachingOptions(options));
        }
        /// <summary>
        /// Set logging options for the request.
        /// </summary>
        /// <param name="requestBuilder">Request builder instance.</param>
        /// <param name="configure">Action to configure logging options.</param>
        public static FluentHttpRequestBuilder WithLoggingOptions(this FluentHttpRequestBuilder requestBuilder, Action <LoggerHttpMiddlewareOptions> configure)
        {
            var options = new LoggerHttpMiddlewareOptions();

            configure?.Invoke(options);
            return(requestBuilder.WithLoggingOptions(options));
        }
        /// <summary>
        /// Sends request and unwrap GraphQL data to be available directly in the `.Data`.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns>Returns content within GraphQL data response object</returns>
        public static async Task <FluentHttpResponse <T> > ReturnAsGqlResponse <T>(this FluentHttpRequestBuilder builder)
        {
            var response = await builder.ReturnAsResponse <GqlResponse <T> >().ConfigureAwait(false);

            return(new FluentHttpResponse <T>(response)
            {
                Data = response.Data != null ? response.Data.Data : default
            });
        /// <summary>
        /// Set request hash options for the request.
        /// </summary>
        /// <param name="requestBuilder">Request builder instance.</param>
        /// <param name="configure">Action to configure options.</param>
        public static FluentHttpRequestBuilder WithRequestHashOptions(this FluentHttpRequestBuilder requestBuilder, Action <RequestHashOptions>?configure)
        {
            RequestHashOptions options;

            if (requestBuilder.Items.TryGetValue(HashOptionsKey, out var result))
            {
                options = (RequestHashOptions)result;
            }
            else
            {
                options = new RequestHashOptions();
            }

            configure?.Invoke(options);
            requestBuilder.Items[HashOptionsKey] = options;
            return(requestBuilder);
        }
 /// <summary>
 /// Set timer warn threshold for request.
 /// </summary>
 /// <param name="requestBuilder">Request builder instance.</param>
 /// <param name="value">Timespan value.</param>
 public static FluentHttpRequestBuilder WithTimerWarnThreshold(this FluentHttpRequestBuilder requestBuilder, TimeSpan value)
 {
     requestBuilder.Items[WarnThresholdOptionKey] = value;
     return(requestBuilder);
 }
Esempio n. 6
0
        /// <summary>
        /// Build FluentHttpRequestBuilder and  call returned FluentHttpRequest's FluentHttpClient SendAsync method.
        /// </summary>
        /// <typeparam name="T">Return type</typeparam>
        /// <param name="builder">FluentHttpRequest</param>
        /// <returns>T</returns>
        public static async Task <T> SendAsync <T>(this FluentHttpRequestBuilder builder)
        {
            var request = builder.Build();

            return(await SendAsync <T>(request));
        }
 /// <summary>
 /// Set request as a GraphQL.
 /// </summary>
 /// <returns></returns>
 public static FluentHttpRequestBuilder AsGql(this FluentHttpRequestBuilder builder, string query) => builder.AsPost().WithBody(new { query });
 /// <summary>
 /// Set request as GraphQL.
 /// </summary>
 ///<returns>Returns request builder for chaining.</returns>
 public static FluentHttpRequestBuilder AsGql(this FluentHttpRequestBuilder builder, GqlQuery query) => builder.AsPost().WithBody(query);
 /// <summary>
 /// Set request method as <c>Trace</c>.
 /// </summary>
 /// <returns>Returns request builder for chaining.</returns>
 public static FluentHttpRequestBuilder AsTrace(this FluentHttpRequestBuilder builder) => builder.WithMethod(HttpMethod.Trace);
 /// <inheritdoc />
 public Task <FluentHttpResponse> Send(FluentHttpRequestBuilder builder)
 {
     return(Send(builder.Build()));
 }
 /// <summary>
 /// Set request method as <c>Delete</c>.
 /// </summary>
 /// <returns>Returns request builder for chaining.</returns>
 public static FluentHttpRequestBuilder AsDelete(this FluentHttpRequestBuilder builder) => builder.WithMethod(HttpMethod.Delete);
 /// <summary>
 /// Set response caching options for the request.
 /// </summary>
 /// <param name="requestBuilder">Request builder instance.</param>
 /// <param name="options">Options to set.</param>
 public static FluentHttpRequestBuilder WithResponseCachingOptions(this FluentHttpRequestBuilder requestBuilder, ResponseCacheHttpMiddlewareOptions options)
 {
     requestBuilder.Items[OptionsKey] = options;
     return(requestBuilder);
 }
 /// <summary>
 /// Set request as a GraphQL.
 /// </summary>
 /// <returns></returns>
 public static FluentHttpRequestBuilder AsGql(this FluentHttpRequestBuilder builder, string query, string?operationName = null) => builder.AsPost().WithBody(new { query, operationName });
 /// <summary>
 /// Set request as GraphQL.
 /// </summary>
 ///<returns>Returns request builder for chaining.</returns>
 public static FluentHttpRequestBuilder AsGql(this FluentHttpRequestBuilder builder, GqlRequest request) => builder.AsPost().WithBody(request);
        /// <summary>
        /// Send request and return as byte array.
        /// </summary>
        /// <returns>Returns content as byte array.</returns>
        public static async Task <byte[]> ReturnAsByteArray(this FluentHttpRequestBuilder builder)
        {
            var response = await builder.ReturnAsResponse().ConfigureAwait(false);

            return(await response.Content.ReadAsByteArrayAsync().ConfigureAwait(false));
        }
        /// <summary>
        /// Send request and read content as string.
        /// </summary>
        /// <returns>Returns content as string.</returns>
        public static async Task <string> ReturnAsString(this FluentHttpRequestBuilder builder)
        {
            var response = await builder.ReturnAsResponse().ConfigureAwait(false);

            return(await response.Content.ReadAsStringAsync().ConfigureAwait(false));
        }
 /// <summary>
 /// Set request method as <c>Patch</c>.
 /// </summary>
 /// <returns>Returns request builder for chaining.</returns>
 public static FluentHttpRequestBuilder AsPatch(this FluentHttpRequestBuilder builder) => builder.WithMethod(HttpMethodPatch);
 /// <summary>
 /// Set logging options for the request.
 /// </summary>
 /// <param name="requestBuilder">Request builder instance.</param>
 /// <param name="options">Logging options to set.</param>
 public static FluentHttpRequestBuilder WithLoggingOptions(this FluentHttpRequestBuilder requestBuilder, LoggerHttpMiddlewareOptions options)
 {
     requestBuilder.Items[LoggingOptionsKey] = options;
     return(requestBuilder);
 }
 /// <summary>
 /// Set request method as <c>Options</c>.
 /// </summary>
 /// <returns>Returns request builder for chaining.</returns>
 public static FluentHttpRequestBuilder AsOptions(this FluentHttpRequestBuilder builder) => builder.WithMethod(HttpMethod.Options);
 /// <summary>
 /// Set request method as <c>Put</c>.
 /// </summary>
 /// <returns>Returns request builder for chaining.</returns>
 public static FluentHttpRequestBuilder AsPut(this FluentHttpRequestBuilder builder) => builder.WithMethod(HttpMethod.Put);
 /// <summary>
 /// Set request method as <c>Head</c>.
 /// </summary>
 /// <returns>Returns request builder for chaining.</returns>
 public static FluentHttpRequestBuilder AsHead(this FluentHttpRequestBuilder builder) => builder.WithMethod(HttpMethod.Head);