/// <summary>
        /// Creates a new <see cref="HttpWebRequest"/> with a <see cref="HttpWebRequest.RequestUri"/> specified
        /// by the given <paramref name="urlTemplate"/> and <paramref name="parameters"/>.
        /// </summary>
        /// <typeparam name="T">The type of the format parameters for <paramref name="urlTemplate"/>.</typeparam>
        /// <param name="urlTemplate">The <see cref="UrlTemplate{T}"/>.</param>
        /// <param name="parameters">The format parameters for the <see cref="UrlTemplate{T}"/>.</param>
        /// <returns>The new <see cref="HttpWebRequest"/>.</returns>
        public static WebRequest CreateHttpWebRequest <T>(this UrlTemplate <T> urlTemplate, T parameters)
        {
            if (urlTemplate == null)
            {
                throw new ArgumentNullException(nameof(urlTemplate));
            }
            var uri = urlTemplate.ToString(parameters);

            return(WebRequest.CreateHttp(uri));
        }
        /// <summary>
        /// Creates a new <see cref="WebRequest"/> with a <see cref="WebRequest.RequestUri"/> specified
        /// by the given <paramref name="urlTemplate"/> and <paramref name="parameters"/>.
        /// </summary>
        /// <param name="urlTemplate">The <see cref="UrlTemplate"/>.</param>
        /// <param name="parameters">The format parameters for the <see cref="UrlTemplate"/>.</param>
        /// <returns>The new <see cref="WebRequest"/>.</returns>
        public static WebRequest CreateWebRequest(this UrlTemplate urlTemplate, object parameters)
        {
            if (urlTemplate == null)
            {
                throw new ArgumentNullException(nameof(urlTemplate));
            }
            var uri = urlTemplate.ToString(parameters);

            return(WebRequest.Create(uri));
        }
        /// <summary>
        /// Send a GET request to the specified Uri with a cancellation token as an asynchronous
        /// operation, and returns the resulting response as a byte array.
        /// </summary>
        /// <param name="httpClient">The HTTP client to perform the request on.</param>
        /// <param name="urlTemplate">The <see cref="UrlTemplate"/>.</param>
        /// <param name="parameters">The format parameters for the <see cref="UrlTemplate"/>.</param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        public static Task <byte[]> GetByteArrayAsync(this HttpClient httpClient, UrlTemplate urlTemplate, object parameters)
        {
            if (httpClient == null)
            {
                throw new ArgumentNullException(nameof(httpClient));
            }
            if (urlTemplate == null)
            {
                throw new ArgumentNullException(nameof(urlTemplate));
            }
            var uri = urlTemplate.ToString(parameters);

            return(httpClient.GetByteArrayAsync(uri));
        }
        /// <summary>
        /// Send a GET request to the specified Uri with a cancellation token as an asynchronous
        /// operation.
        /// </summary>
        /// <param name="httpClient">The HTTP client to perform the request on.</param>
        /// <param name="urlTemplate">The <see cref="UrlTemplate"/>.</param>
        /// <param name="parameters">The format parameters for the <see cref="UrlTemplate"/>.</param>
        /// <param name="completionOption">An HTTP completion option value that indicates when the operation should be considered completed.</param>
        /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        public static Task <HttpResponseMessage> GetAsync(this HttpClient httpClient, UrlTemplate urlTemplate, object parameters, HttpCompletionOption completionOption, CancellationToken cancellationToken = default)
        {
            if (httpClient == null)
            {
                throw new ArgumentNullException(nameof(httpClient));
            }
            if (urlTemplate == null)
            {
                throw new ArgumentNullException(nameof(urlTemplate));
            }
            var uri = urlTemplate.ToString(parameters);

            return(httpClient.GetAsync(uri, completionOption, cancellationToken));
        }
        /// <summary>
        /// Send a PUT request to the specified Uri with a cancellation token as an asynchronous
        /// operation.
        /// </summary>
        /// <typeparam name="T">The type of the format parameters for <paramref name="urlTemplate"/>.</typeparam>
        /// <param name="httpClient">The HTTP client to perform the request on.</param>
        /// <param name="urlTemplate">The <see cref="UrlTemplate{T}"/>.</param>
        /// <param name="parameters">The format parameters for the <see cref="UrlTemplate{T}"/>.</param>
        /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        public static Task <HttpResponseMessage> PutAsync <T>(this HttpClient httpClient, UrlTemplate <T> urlTemplate, T parameters, HttpContent content, CancellationToken cancellationToken = default)
        {
            if (httpClient == null)
            {
                throw new ArgumentNullException(nameof(httpClient));
            }
            if (urlTemplate == null)
            {
                throw new ArgumentNullException(nameof(urlTemplate));
            }
            var uri = urlTemplate.ToString(parameters);

            return(httpClient.PutAsync(uri, content, cancellationToken));
        }
        /// <summary>
        /// Send a GET request to the specified Uri with a cancellation token as an asynchronous
        /// operation, and returns the resulting response as a <see cref="string"/>.
        /// </summary>
        /// <typeparam name="T">The type of the format parameters for <paramref name="urlTemplate"/>.</typeparam>
        /// <param name="httpClient">The HTTP client to perform the request on.</param>
        /// <param name="urlTemplate">The <see cref="UrlTemplate{T}"/>.</param>
        /// <param name="parameters">The format parameters for the <see cref="UrlTemplate{T}"/>.</param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        public static Task <string> GetStringAsync <T>(this HttpClient httpClient, UrlTemplate <T> urlTemplate, T parameters)
        {
            if (httpClient == null)
            {
                throw new ArgumentNullException(nameof(httpClient));
            }
            if (urlTemplate == null)
            {
                throw new ArgumentNullException(nameof(urlTemplate));
            }
            var uri = urlTemplate.ToString(parameters);

            return(httpClient.GetStringAsync(uri));
        }
        /// <summary>
        /// Creates a <see cref="HttpRequestMessage"/> for the specified <see cref="HttpClient"/>.
        /// </summary>
        /// <typeparam name="T">The type of the format parameters for <paramref name="urlTemplate"/>.</typeparam>
        /// <param name="httpClient">The HTTP client to perform the request on.</param>
        /// <param name="method">The HTTP method.</param>
        /// <param name="urlTemplate">The <see cref="UrlTemplate{T}"/>.</param>
        /// <param name="parameters">The format parameters for the <see cref="UrlTemplate{T}"/>.</param>
        /// <returns>The <see cref="HttpRequestMessage"/>.</returns>
        public static HttpRequestMessage CreateRequestMessage <T>(this HttpClient httpClient, HttpMethod method, UrlTemplate <T> urlTemplate, T parameters)
        {
            if (httpClient == null)
            {
                throw new ArgumentNullException(nameof(httpClient));
            }
            if (method == null)
            {
                throw new ArgumentNullException(nameof(method));
            }
            if (urlTemplate == null)
            {
                throw new ArgumentNullException(nameof(urlTemplate));
            }
            var uri = urlTemplate.ToString(parameters);

            return(new HttpRequestMessage(method, uri));
        }