Exemple #1
0
        /// <summary>
        /// Sends a POST request using specified fluent builder as an asynchronous operation.
        /// </summary>
        /// <param name="fluentClient">The <see cref="IFluentClient"/> used to send request.</param>
        /// <param name="builder">The fluent builder factory.</param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="fluentClient" /> or <paramref name="builder" /> is <see langword="null" />.</exception>
        public static async Task <HttpResponseMessage> PostAsync(this IFluentClient fluentClient, Action <FormBuilder> builder)
        {
            if (fluentClient == null)
            {
                throw new ArgumentNullException(nameof(fluentClient));
            }

            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var httpClient     = fluentClient.HttpClient;
            var requestMessage = new HttpRequestMessage(HttpMethod.Post, httpClient.BaseAddress);

            requestMessage.SetContentSerializer(fluentClient.ContentSerializer);

            var fluentBuilder = new FormBuilder(requestMessage);

            builder(fluentBuilder);

            var response = await FluentDispatcher.SendAsync(httpClient, requestMessage).ConfigureAwait(false);

            return(response);
        }
Exemple #2
0
        /// <summary>
        /// Sends a request using specified request message as an asynchronous operation.
        /// </summary>
        /// <param name="fluentClient">The <see cref="IFluentClient"/> used to send request.</param>
        /// <param name="requestMessage">The request message to send.</param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="fluentClient" /> or <paramref name="requestMessage" /> is <see langword="null" />.</exception>
        public static async Task <HttpResponseMessage> SendAsync(this IFluentClient fluentClient, HttpRequestMessage requestMessage)
        {
            if (fluentClient == null)
            {
                throw new ArgumentNullException(nameof(fluentClient));
            }

            if (requestMessage == null)
            {
                throw new ArgumentNullException(nameof(requestMessage));
            }

            var httpClient = fluentClient.HttpClient;

            requestMessage.SetContentSerializer(fluentClient.ContentSerializer);

            var response = await FluentDispatcher.SendAsync(httpClient, requestMessage).ConfigureAwait(false);

            return(response);
        }
Exemple #3
0
        /// <summary>
        /// Sends a GET request using specified fluent <paramref name="builder" /> as an asynchronous operation.
        /// </summary>
        /// <param name="httpClient">The <see cref="HttpClient"/> used to send request.</param>
        /// <param name="builder">The fluent builder factory.</param>
        /// <returns>
        /// The task object representing the asynchronous operation.
        /// </returns>
        /// <exception cref="ArgumentNullException"><paramref name="httpClient" /> or <paramref name="builder" /> is <see langword="null" />.</exception>
        public static async Task <HttpResponseMessage> GetAsync(this HttpClient httpClient, Action <QueryBuilder> builder)
        {
            if (httpClient == null)
            {
                throw new ArgumentNullException(nameof(httpClient));
            }

            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var requestMessage = new HttpRequestMessage(HttpMethod.Get, httpClient.BaseAddress);

            var fluentBuilder = new QueryBuilder(requestMessage);

            builder(fluentBuilder);

            var response = await FluentDispatcher.SendAsync(httpClient, requestMessage).ConfigureAwait(false);

            return(response);
        }