From 0e08e6fd6a8600afddeb76f0fa0da94c48b240c7 Mon Sep 17 00:00:00 2001 From: Anders Bjerner Date: Sat, 27 Jan 2024 18:35:18 +0100 Subject: [PATCH] Updated .editorconfig and updated all .cs files to use file-scoped namespace declarations --- src/.editorconfig | 27 +- .../Client/HttpClient.Delete.cs | 98 +- .../Client/HttpClient.Get.cs | 98 +- .../Client/HttpClient.Patch.cs | 350 ++- .../Client/HttpClient.Post.cs | 528 +++-- .../Client/HttpClient.Put.cs | 528 +++-- .../Client/HttpClient.cs | 1891 ++++++++--------- .../Client/HttpClientAsyncExtensions.cs | 1640 +++++++------- .../Client/HttpClientExtensions.cs | 1640 +++++++------- .../Client/IHttpClient.cs | 1336 ++++++------ .../Client/IHttpClient2.cs | 34 +- .../Client/IHttpClientAsync.cs | 34 +- .../Collections/HttpCookieCollection.cs | 52 +- .../Collections/HttpHeaderCollection.cs | 294 ++- .../Collections/HttpPostData.cs | 360 ++-- .../Collections/HttpQueryString.cs | 632 +++--- .../Collections/HttpQueryStringExtensions.cs | 164 +- .../Collections/IHttpCookieCollection.cs | 24 +- .../Collections/IHttpHeaderCollection.cs | 156 +- .../Collections/IHttpPostData.cs | 230 +- .../Collections/IHttpQueryString.cs | 264 ++- .../Exceptions/HttpException.cs | 50 +- .../Exceptions/IHttpException.cs | 26 +- src/Skybrud.Essentials.Http/HttpConstants.cs | 84 +- src/Skybrud.Essentials.Http/HttpMethod.cs | 68 +- .../HttpPostFileValue.cs | 192 +- src/Skybrud.Essentials.Http/HttpPostValue.cs | 96 +- .../HttpRequest.Async.cs | 180 +- src/Skybrud.Essentials.Http/HttpRequest.cs | 1570 +++++++------- .../HttpRequestExtensions.cs | 470 ++-- .../HttpRequestXmlExtensions.cs | 116 +- src/Skybrud.Essentials.Http/HttpResponse.cs | 354 ++- .../HttpResponseBase.cs | 520 +++-- .../HttpResponseExtensions.cs | 238 +-- src/Skybrud.Essentials.Http/HttpUtils.Http.cs | 704 +++--- .../HttpUtils.Requests.cs | 612 +++--- src/Skybrud.Essentials.Http/HttpUtils.cs | 12 +- src/Skybrud.Essentials.Http/IHttpPostValue.cs | 34 +- src/Skybrud.Essentials.Http/IHttpRequest.cs | 288 ++- src/Skybrud.Essentials.Http/IHttpResponse.cs | 82 +- .../OAuth/Exceptions/OAuthException.cs | 44 +- .../OAuth/Models/OAuthAccessToken.cs | 100 +- .../OAuth/Models/OAuthRequestToken.cs | 110 +- .../OAuth/OAuthClient.cs | 616 +++--- .../OAuth/OAuthUtils.cs | 36 +- .../Responses/OAuthAccessTokenResponse.cs | 68 +- .../Responses/OAuthRequestTokenResponse.cs | 68 +- .../Options/IHttpGetOptions.cs | 26 +- .../Options/IHttpPostOptions.cs | 26 +- .../Options/IHttpRequestOptions.cs | 20 +- 50 files changed, 8556 insertions(+), 8634 deletions(-) diff --git a/src/.editorconfig b/src/.editorconfig index 0a91f31..461eecf 100644 --- a/src/.editorconfig +++ b/src/.editorconfig @@ -1,3 +1,5 @@ +# Version 1.0.6 + # Remove the line below if you want to inherit .editorconfig settings from higher directories root = true @@ -10,6 +12,7 @@ root = true indent_size = 4 indent_style = space tab_width = 4 +trim_trailing_whitespace = true # New line preferences end_of_line = crlf @@ -19,7 +22,7 @@ insert_final_newline = false # Organize usings dotnet_separate_import_directive_groups = false -dotnet_sort_system_directives_first = false +dotnet_sort_system_directives_first = true # this. and Me. preferences dotnet_style_qualification_for_event = false:silent @@ -28,8 +31,8 @@ dotnet_style_qualification_for_method = false:silent dotnet_style_qualification_for_property = false:silent # Language keywords vs BCL types preferences -dotnet_style_predefined_type_for_locals_parameters_members = true:silent -dotnet_style_predefined_type_for_member_access = true:silent +dotnet_style_predefined_type_for_locals_parameters_members = true:warning +dotnet_style_predefined_type_for_member_access = true:warning # Parentheses preferences dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent @@ -194,4 +197,20 @@ dotnet_naming_style.pascal_case.capitalization = pascal_case dotnet_naming_style.begins_with_i.required_prefix = I dotnet_naming_style.begins_with_i.required_suffix = dotnet_naming_style.begins_with_i.word_separator = -dotnet_naming_style.begins_with_i.capitalization = pascal_case \ No newline at end of file +dotnet_naming_style.begins_with_i.capitalization = pascal_case + +# Define what we will treat as private fields +dotnet_naming_symbols.private_fields.applicable_kinds = field +dotnet_naming_symbols.private_fields.applicable_accessibilities = private + +# Define rule that something must begin with an underscore and be in camel case +dotnet_naming_style.require_underscore_prefix_and_camel_case.required_prefix = _ +dotnet_naming_style.require_underscore_prefix_and_camel_case.capitalization = camel_case + +# Apply our rule to private fields +dotnet_naming_rule.private_fields_must_begin_with_underscore_and_be_in_camel_case.symbols = private_fields +dotnet_naming_rule.private_fields_must_begin_with_underscore_and_be_in_camel_case.style = require_underscore_prefix_and_camel_case +dotnet_naming_rule.private_fields_must_begin_with_underscore_and_be_in_camel_case.severity = warning + +# Prefer file-scoped namespace declarations +csharp_style_namespace_declarations = file_scoped:warning diff --git a/src/Skybrud.Essentials.Http/Client/HttpClient.Delete.cs b/src/Skybrud.Essentials.Http/Client/HttpClient.Delete.cs index cac6348..6844e52 100644 --- a/src/Skybrud.Essentials.Http/Client/HttpClient.Delete.cs +++ b/src/Skybrud.Essentials.Http/Client/HttpClient.Delete.cs @@ -3,60 +3,58 @@ using Skybrud.Essentials.Http.Collections; using Skybrud.Essentials.Http.Options; -namespace Skybrud.Essentials.Http.Client { - - public partial class HttpClient { - - /// - /// Makes a HTTP DELETE request to the specified . - /// - /// The URL of the request. - /// An instance of representing the response. - public virtual IHttpResponse Delete(string url) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return GetResponse(HttpRequest.Delete(url)); - } - - /// - /// Makes a DELETE request to the specified . - /// - /// The URL of the request. - /// The options for the call to the specified . - /// An instance of representing the response. - [Obsolete("Use 'GetResponse' method and 'IHttpRequestOptions' class as parameter instead.")] - public virtual IHttpResponse Delete(string url, IHttpGetOptions options) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - if (options == null) throw new ArgumentNullException(nameof(options)); - return GetResponse(HttpRequest.Delete(url, options.GetQueryString())); - } - - /// - /// Makes a DELETE request to the specified . - /// - /// The URL of the request. - /// The query string of the request. - /// An instance of representing the response. - public virtual IHttpResponse Delete(string url, IHttpQueryString queryString) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return GetResponse(HttpRequest.Delete(url, queryString)); - } +namespace Skybrud.Essentials.Http.Client; + +public partial class HttpClient { + + /// + /// Makes a HTTP DELETE request to the specified . + /// + /// The URL of the request. + /// An instance of representing the response. + public virtual IHttpResponse Delete(string url) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return GetResponse(HttpRequest.Delete(url)); + } -#if NAME_VALUE_COLLECTION + /// + /// Makes a DELETE request to the specified . + /// + /// The URL of the request. + /// The options for the call to the specified . + /// An instance of representing the response. + [Obsolete("Use 'GetResponse' method and 'IHttpRequestOptions' class as parameter instead.")] + public virtual IHttpResponse Delete(string url, IHttpGetOptions options) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + if (options == null) throw new ArgumentNullException(nameof(options)); + return GetResponse(HttpRequest.Delete(url, options.GetQueryString())); + } - /// - /// Makes a DELETE request to the specified . - /// - /// The URL of the request. - /// The query string of the request. - /// An instance of representing the response. - public virtual IHttpResponse Delete(string url, NameValueCollection? queryString) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return GetResponse(HttpRequest.Delete(url, query)); - } + /// + /// Makes a DELETE request to the specified . + /// + /// The URL of the request. + /// The query string of the request. + /// An instance of representing the response. + public virtual IHttpResponse Delete(string url, IHttpQueryString queryString) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return GetResponse(HttpRequest.Delete(url, queryString)); + } -#endif +#if NAME_VALUE_COLLECTION + /// + /// Makes a DELETE request to the specified . + /// + /// The URL of the request. + /// The query string of the request. + /// An instance of representing the response. + public virtual IHttpResponse Delete(string url, NameValueCollection? queryString) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return GetResponse(HttpRequest.Delete(url, query)); } +#endif + } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/Client/HttpClient.Get.cs b/src/Skybrud.Essentials.Http/Client/HttpClient.Get.cs index 390b904..5d507ee 100644 --- a/src/Skybrud.Essentials.Http/Client/HttpClient.Get.cs +++ b/src/Skybrud.Essentials.Http/Client/HttpClient.Get.cs @@ -3,60 +3,58 @@ using Skybrud.Essentials.Http.Collections; using Skybrud.Essentials.Http.Options; -namespace Skybrud.Essentials.Http.Client { - - public partial class HttpClient { - - /// - /// Makes a HTTP GET request to the specified . - /// - /// The URL of the request. - /// An instance of representing the response. - public virtual IHttpResponse Get(string url) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return GetResponse(HttpRequest.Get(url)); - } - - /// - /// Makes a GET request to the specified . - /// - /// The URL of the request. - /// The options for the call to the specified . - /// An instance of representing the response. - [Obsolete("Use 'GetResponse' method and 'IHttpRequestOptions' class as parameter instead.")] - public virtual IHttpResponse Get(string url, IHttpGetOptions options) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - if (options == null) throw new ArgumentNullException(nameof(options)); - return GetResponse(HttpRequest.Get(url, options.GetQueryString())); - } - - /// - /// Makes a GET request to the specified . - /// - /// The URL of the request. - /// The query string of the request. - /// An instance of representing the response. - public virtual IHttpResponse Get(string url, IHttpQueryString queryString) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return GetResponse(HttpRequest.Get(url, queryString)); - } +namespace Skybrud.Essentials.Http.Client; + +public partial class HttpClient { + + /// + /// Makes a HTTP GET request to the specified . + /// + /// The URL of the request. + /// An instance of representing the response. + public virtual IHttpResponse Get(string url) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return GetResponse(HttpRequest.Get(url)); + } -#if NAME_VALUE_COLLECTION + /// + /// Makes a GET request to the specified . + /// + /// The URL of the request. + /// The options for the call to the specified . + /// An instance of representing the response. + [Obsolete("Use 'GetResponse' method and 'IHttpRequestOptions' class as parameter instead.")] + public virtual IHttpResponse Get(string url, IHttpGetOptions options) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + if (options == null) throw new ArgumentNullException(nameof(options)); + return GetResponse(HttpRequest.Get(url, options.GetQueryString())); + } - /// - /// Makes a GET request to the specified . - /// - /// The URL of the request. - /// The query string of the request. - /// An instance of representing the response. - public virtual IHttpResponse Get(string url, NameValueCollection? queryString) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return GetResponse(HttpRequest.Get(url, query)); - } + /// + /// Makes a GET request to the specified . + /// + /// The URL of the request. + /// The query string of the request. + /// An instance of representing the response. + public virtual IHttpResponse Get(string url, IHttpQueryString queryString) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return GetResponse(HttpRequest.Get(url, queryString)); + } -#endif +#if NAME_VALUE_COLLECTION + /// + /// Makes a GET request to the specified . + /// + /// The URL of the request. + /// The query string of the request. + /// An instance of representing the response. + public virtual IHttpResponse Get(string url, NameValueCollection? queryString) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return GetResponse(HttpRequest.Get(url, query)); } +#endif + } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/Client/HttpClient.Patch.cs b/src/Skybrud.Essentials.Http/Client/HttpClient.Patch.cs index be3f300..a625498 100644 --- a/src/Skybrud.Essentials.Http/Client/HttpClient.Patch.cs +++ b/src/Skybrud.Essentials.Http/Client/HttpClient.Patch.cs @@ -6,196 +6,196 @@ using Skybrud.Essentials.Http.Collections; using Skybrud.Essentials.Http.Options; -namespace Skybrud.Essentials.Http.Client { +namespace Skybrud.Essentials.Http.Client; - public partial class HttpClient { +public partial class HttpClient { - /// - /// Makes a PATCH request to the specified . - /// - /// The URL of the request. - /// An instance of representing the response. - public virtual IHttpResponse Patch(string url) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return GetResponse(HttpRequest.Patch(url)); - } + /// + /// Makes a PATCH request to the specified . + /// + /// The URL of the request. + /// An instance of representing the response. + public virtual IHttpResponse Patch(string url) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return GetResponse(HttpRequest.Patch(url)); + } - /// - /// Makes a PATCH request to the specified . - /// - /// The URL of the request. - /// The options for the call to the specified . - /// An instance of representing the response. - [Obsolete("Use 'GetResponse' method and 'IHttpRequestOptions' class as parameter instead.")] - public virtual IHttpResponse Patch(string url, IHttpGetOptions options) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - if (options == null) throw new ArgumentNullException(nameof(options)); - return GetResponse(HttpRequest.Patch(url, options.GetQueryString())); - } + /// + /// Makes a PATCH request to the specified . + /// + /// The URL of the request. + /// The options for the call to the specified . + /// An instance of representing the response. + [Obsolete("Use 'GetResponse' method and 'IHttpRequestOptions' class as parameter instead.")] + public virtual IHttpResponse Patch(string url, IHttpGetOptions options) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + if (options == null) throw new ArgumentNullException(nameof(options)); + return GetResponse(HttpRequest.Patch(url, options.GetQueryString())); + } - /// - /// Makes a PATCH request to the specified . - /// - /// The URL of the request. - /// The options for the call to the specified . - /// An instance of representing the response. - [Obsolete("Use 'GetResponse' method and 'IHttpRequestOptions' class as parameter instead.")] - public virtual IHttpResponse Patch(string url, IHttpPostOptions options) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - if (options == null) throw new ArgumentNullException(nameof(options)); - return GetResponse(HttpRequest.Patch(url, options.GetQueryString(), options.GetPostData())); - } + /// + /// Makes a PATCH request to the specified . + /// + /// The URL of the request. + /// The options for the call to the specified . + /// An instance of representing the response. + [Obsolete("Use 'GetResponse' method and 'IHttpRequestOptions' class as parameter instead.")] + public virtual IHttpResponse Patch(string url, IHttpPostOptions options) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + if (options == null) throw new ArgumentNullException(nameof(options)); + return GetResponse(HttpRequest.Patch(url, options.GetQueryString(), options.GetPostData())); + } - /// - /// Makes a PATCH request to the specified . - /// - /// The base URL of the request (no query string). - /// The query string. - /// An instance of representing the raw response. - public virtual IHttpResponse Patch(string url, IHttpQueryString queryString) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return GetResponse(HttpRequest.Patch(url, queryString)); - } + /// + /// Makes a PATCH request to the specified . + /// + /// The base URL of the request (no query string). + /// The query string. + /// An instance of representing the raw response. + public virtual IHttpResponse Patch(string url, IHttpQueryString queryString) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return GetResponse(HttpRequest.Patch(url, queryString)); + } - /// - /// Makes a PATCH request to the specified . - /// - /// The base URL of the request (no query string). - /// The POST data. - /// An instance of representing the raw response. - public virtual IHttpResponse Patch(string url, IHttpPostData postData) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return GetResponse(HttpRequest.Patch(url, postData)); - } + /// + /// Makes a PATCH request to the specified . + /// + /// The base URL of the request (no query string). + /// The POST data. + /// An instance of representing the raw response. + public virtual IHttpResponse Patch(string url, IHttpPostData postData) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return GetResponse(HttpRequest.Patch(url, postData)); + } - /// - /// Makes a PATCH request to the specified . - /// - /// The URL of the request. - /// The query string of the request. - /// The body of the request. - /// An instance of representing the response. - public virtual IHttpResponse Patch(string url, IHttpQueryString queryString, IHttpPostData postData) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return GetResponse(HttpRequest.Patch(url, queryString, postData)); - } + /// + /// Makes a PATCH request to the specified . + /// + /// The URL of the request. + /// The query string of the request. + /// The body of the request. + /// An instance of representing the response. + public virtual IHttpResponse Patch(string url, IHttpQueryString queryString, IHttpPostData postData) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return GetResponse(HttpRequest.Patch(url, queryString, postData)); + } - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The URL of the request. - /// The query string of the request. - /// The content type of the request - eg. application/json. - /// The body of the request. - /// An instance of representing the response. - public virtual IHttpResponse Patch(string url, IHttpQueryString queryString, string contentType, string body) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return GetResponse(HttpRequest.Patch(url, queryString).SetContentType(contentType).SetBody(body)); - } + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The URL of the request. + /// The query string of the request. + /// The content type of the request - eg. application/json. + /// The body of the request. + /// An instance of representing the response. + public virtual IHttpResponse Patch(string url, IHttpQueryString queryString, string contentType, string body) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return GetResponse(HttpRequest.Patch(url, queryString).SetContentType(contentType).SetBody(body)); + } - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The body of the request. - /// An instance of representing the raw response. - public virtual IHttpResponse Patch(string url, JToken body) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - if (body == null) throw new ArgumentNullException(nameof(body)); - return GetResponse(HttpRequest.Patch(url, body)); - } + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The body of the request. + /// An instance of representing the raw response. + public virtual IHttpResponse Patch(string url, JToken body) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + if (body == null) throw new ArgumentNullException(nameof(body)); + return GetResponse(HttpRequest.Patch(url, body)); + } - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The body of the request. - /// The formatting to be used when serializing . - /// An instance of representing the raw response. - public virtual IHttpResponse Patch(string url, JToken body, Formatting formatting) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - if (body == null) throw new ArgumentNullException(nameof(body)); - return GetResponse(HttpRequest.Patch(url, body, formatting)); - } + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The body of the request. + /// The formatting to be used when serializing . + /// An instance of representing the raw response. + public virtual IHttpResponse Patch(string url, JToken body, Formatting formatting) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + if (body == null) throw new ArgumentNullException(nameof(body)); + return GetResponse(HttpRequest.Patch(url, body, formatting)); + } - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - public virtual IHttpResponse Patch(string url, IHttpQueryString queryString, JToken body) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - if (body == null) throw new ArgumentNullException(nameof(body)); - return GetResponse(HttpRequest.Patch(url, queryString, body)); - } + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + public virtual IHttpResponse Patch(string url, IHttpQueryString queryString, JToken body) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + if (body == null) throw new ArgumentNullException(nameof(body)); + return GetResponse(HttpRequest.Patch(url, queryString, body)); + } - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// The formatting to be used when serializing . - /// An instance of representing the raw response. - public virtual IHttpResponse Patch(string url, IHttpQueryString queryString, JToken body, Formatting formatting) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - if (body == null) throw new ArgumentNullException(nameof(body)); - return GetResponse(HttpRequest.Patch(url, queryString, body, formatting)); - } + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// The formatting to be used when serializing . + /// An instance of representing the raw response. + public virtual IHttpResponse Patch(string url, IHttpQueryString queryString, JToken body, Formatting formatting) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + if (body == null) throw new ArgumentNullException(nameof(body)); + return GetResponse(HttpRequest.Patch(url, queryString, body, formatting)); + } - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The body of the request. - /// An instance of representing the raw response. - public virtual IHttpResponse Patch(string url, XNode body) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - if (body == null) throw new ArgumentNullException(nameof(body)); - return GetResponse(HttpRequest.Patch(url, body)); - } + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The body of the request. + /// An instance of representing the raw response. + public virtual IHttpResponse Patch(string url, XNode body) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + if (body == null) throw new ArgumentNullException(nameof(body)); + return GetResponse(HttpRequest.Patch(url, body)); + } - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The body of the request. - /// The options to be used when serializing . - /// An instance of representing the raw response. - public virtual IHttpResponse Patch(string url, XNode body, SaveOptions options) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - if (body == null) throw new ArgumentNullException(nameof(body)); - return GetResponse(HttpRequest.Patch(url, body, options)); - } + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The body of the request. + /// The options to be used when serializing . + /// An instance of representing the raw response. + public virtual IHttpResponse Patch(string url, XNode body, SaveOptions options) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + if (body == null) throw new ArgumentNullException(nameof(body)); + return GetResponse(HttpRequest.Patch(url, body, options)); + } - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - public virtual IHttpResponse Patch(string url, IHttpQueryString queryString, XNode body) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - if (body == null) throw new ArgumentNullException(nameof(body)); - return GetResponse(HttpRequest.Patch(url, queryString, body)); - } + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + public virtual IHttpResponse Patch(string url, IHttpQueryString queryString, XNode body) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + if (body == null) throw new ArgumentNullException(nameof(body)); + return GetResponse(HttpRequest.Patch(url, queryString, body)); + } - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// The options to be used when serializing . - /// An instance of representing the raw response. - public virtual IHttpResponse Patch(string url, IHttpQueryString queryString, XNode body, SaveOptions options) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - if (body == null) throw new ArgumentNullException(nameof(body)); - return GetResponse(HttpRequest.Patch(url, queryString, body, options)); - } + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// The options to be used when serializing . + /// An instance of representing the raw response. + public virtual IHttpResponse Patch(string url, IHttpQueryString queryString, XNode body, SaveOptions options) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + if (body == null) throw new ArgumentNullException(nameof(body)); + return GetResponse(HttpRequest.Patch(url, queryString, body, options)); + } #if NAME_VALUE_COLLECTION @@ -299,6 +299,4 @@ public virtual IHttpResponse Patch(string url, NameValueCollection? queryString, #endif - } - } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/Client/HttpClient.Post.cs b/src/Skybrud.Essentials.Http/Client/HttpClient.Post.cs index 40ee6f6..a8b9731 100644 --- a/src/Skybrud.Essentials.Http/Client/HttpClient.Post.cs +++ b/src/Skybrud.Essentials.Http/Client/HttpClient.Post.cs @@ -6,297 +6,295 @@ using Skybrud.Essentials.Http.Collections; using Skybrud.Essentials.Http.Options; -namespace Skybrud.Essentials.Http.Client { +namespace Skybrud.Essentials.Http.Client; - public partial class HttpClient { +public partial class HttpClient { - /// - /// Makes a POST request to the specified . - /// - /// The URL of the request. - /// An instance of representing the response. - public virtual IHttpResponse Post(string url) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return GetResponse(HttpRequest.Post(url)); - } + /// + /// Makes a POST request to the specified . + /// + /// The URL of the request. + /// An instance of representing the response. + public virtual IHttpResponse Post(string url) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return GetResponse(HttpRequest.Post(url)); + } - /// - /// Makes a POST request to the specified . - /// - /// The URL of the request. - /// The options for the call to the specified . - /// An instance of representing the response. - [Obsolete("Use 'GetResponse' method and 'IHttpRequestOptions' class as parameter instead.")] - public virtual IHttpResponse Post(string url, IHttpGetOptions? options) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return GetResponse(HttpRequest.Post(url, options?.GetQueryString())); - } + /// + /// Makes a POST request to the specified . + /// + /// The URL of the request. + /// The options for the call to the specified . + /// An instance of representing the response. + [Obsolete("Use 'GetResponse' method and 'IHttpRequestOptions' class as parameter instead.")] + public virtual IHttpResponse Post(string url, IHttpGetOptions? options) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return GetResponse(HttpRequest.Post(url, options?.GetQueryString())); + } - /// - /// Makes a POST request to the specified . - /// - /// The URL of the request. - /// The options for the call to the specified . - /// An instance of representing the response. - [Obsolete("Use 'GetResponse' method and 'IHttpRequestOptions' class as parameter instead.")] - public virtual IHttpResponse Post(string url, IHttpPostOptions? options) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return GetResponse(HttpRequest.Post(url, options?.GetQueryString(), options?.GetPostData())); - } + /// + /// Makes a POST request to the specified . + /// + /// The URL of the request. + /// The options for the call to the specified . + /// An instance of representing the response. + [Obsolete("Use 'GetResponse' method and 'IHttpRequestOptions' class as parameter instead.")] + public virtual IHttpResponse Post(string url, IHttpPostOptions? options) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return GetResponse(HttpRequest.Post(url, options?.GetQueryString(), options?.GetPostData())); + } - /// - /// Makes a POST request to the specified . - /// - /// The base URL of the request (no query string). - /// The query string. - /// An instance of representing the raw response. - public virtual IHttpResponse Post(string url, IHttpQueryString? queryString) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return GetResponse(HttpRequest.Post(url, queryString)); - } + /// + /// Makes a POST request to the specified . + /// + /// The base URL of the request (no query string). + /// The query string. + /// An instance of representing the raw response. + public virtual IHttpResponse Post(string url, IHttpQueryString? queryString) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return GetResponse(HttpRequest.Post(url, queryString)); + } - /// - /// Makes a POST request to the specified . - /// - /// The base URL of the request (no query string). - /// The POST data. - /// An instance of representing the raw response. - public virtual IHttpResponse Post(string url, IHttpPostData? postData) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return GetResponse(HttpRequest.Post(url, postData)); - } + /// + /// Makes a POST request to the specified . + /// + /// The base URL of the request (no query string). + /// The POST data. + /// An instance of representing the raw response. + public virtual IHttpResponse Post(string url, IHttpPostData? postData) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return GetResponse(HttpRequest.Post(url, postData)); + } - /// - /// Makes a POST request to the specified . - /// - /// The URL of the request. - /// The query string of the request. - /// The body of the request. - /// An instance of representing the response. - public virtual IHttpResponse Post(string url, IHttpQueryString? queryString, IHttpPostData? postData) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return GetResponse(HttpRequest.Post(url, queryString, postData)); - } + /// + /// Makes a POST request to the specified . + /// + /// The URL of the request. + /// The query string of the request. + /// The body of the request. + /// An instance of representing the response. + public virtual IHttpResponse Post(string url, IHttpQueryString? queryString, IHttpPostData? postData) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return GetResponse(HttpRequest.Post(url, queryString, postData)); + } - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The URL of the request. - /// The query string of the request. - /// The content type of the request - eg. application/json. - /// The body of the request. - /// An instance of representing the response. - public virtual IHttpResponse Post(string url, IHttpQueryString? queryString, string contentType, string body) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return GetResponse(HttpRequest.Post(url, queryString).SetContentType(contentType).SetBody(body)); - } + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The URL of the request. + /// The query string of the request. + /// The content type of the request - eg. application/json. + /// The body of the request. + /// An instance of representing the response. + public virtual IHttpResponse Post(string url, IHttpQueryString? queryString, string contentType, string body) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return GetResponse(HttpRequest.Post(url, queryString).SetContentType(contentType).SetBody(body)); + } - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The body of the request. - /// An instance of representing the raw response. - public virtual IHttpResponse Post(string url, JToken body) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - if (body == null) throw new ArgumentNullException(nameof(body)); - return GetResponse(HttpRequest.Post(url, body)); - } + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The body of the request. + /// An instance of representing the raw response. + public virtual IHttpResponse Post(string url, JToken body) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + if (body == null) throw new ArgumentNullException(nameof(body)); + return GetResponse(HttpRequest.Post(url, body)); + } - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The body of the request. - /// The formatting to be used when serializing . - /// An instance of representing the raw response. - public virtual IHttpResponse Post(string url, JToken body, Formatting formatting) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - if (body == null) throw new ArgumentNullException(nameof(body)); - return GetResponse(HttpRequest.Post(url, body, formatting)); - } + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The body of the request. + /// The formatting to be used when serializing . + /// An instance of representing the raw response. + public virtual IHttpResponse Post(string url, JToken body, Formatting formatting) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + if (body == null) throw new ArgumentNullException(nameof(body)); + return GetResponse(HttpRequest.Post(url, body, formatting)); + } - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - public virtual IHttpResponse Post(string url, IHttpQueryString? queryString, JToken body) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - if (body == null) throw new ArgumentNullException(nameof(body)); - return GetResponse(HttpRequest.Post(url, queryString, body)); - } + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + public virtual IHttpResponse Post(string url, IHttpQueryString? queryString, JToken body) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + if (body == null) throw new ArgumentNullException(nameof(body)); + return GetResponse(HttpRequest.Post(url, queryString, body)); + } - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// The formatting to be used when serializing . - /// An instance of representing the raw response. - public virtual IHttpResponse Post(string url, IHttpQueryString? queryString, JToken body, Formatting formatting) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - if (body == null) throw new ArgumentNullException(nameof(body)); - return GetResponse(HttpRequest.Post(url, queryString, body, formatting)); - } + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// The formatting to be used when serializing . + /// An instance of representing the raw response. + public virtual IHttpResponse Post(string url, IHttpQueryString? queryString, JToken body, Formatting formatting) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + if (body == null) throw new ArgumentNullException(nameof(body)); + return GetResponse(HttpRequest.Post(url, queryString, body, formatting)); + } - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The body of the request. - /// An instance of representing the raw response. - public virtual IHttpResponse Post(string url, XNode body) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - if (body == null) throw new ArgumentNullException(nameof(body)); - return GetResponse(HttpRequest.Post(url, body)); - } + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The body of the request. + /// An instance of representing the raw response. + public virtual IHttpResponse Post(string url, XNode body) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + if (body == null) throw new ArgumentNullException(nameof(body)); + return GetResponse(HttpRequest.Post(url, body)); + } - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The body of the request. - /// The options to be used when serializing . - /// An instance of representing the raw response. - public virtual IHttpResponse Post(string url, XNode body, SaveOptions options) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - if (body == null) throw new ArgumentNullException(nameof(body)); - return GetResponse(HttpRequest.Post(url, body, options)); - } + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The body of the request. + /// The options to be used when serializing . + /// An instance of representing the raw response. + public virtual IHttpResponse Post(string url, XNode body, SaveOptions options) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + if (body == null) throw new ArgumentNullException(nameof(body)); + return GetResponse(HttpRequest.Post(url, body, options)); + } - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - public virtual IHttpResponse Post(string url, IHttpQueryString? queryString, XNode body) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - if (body == null) throw new ArgumentNullException(nameof(body)); - return GetResponse(HttpRequest.Post(url, queryString, body)); - } + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + public virtual IHttpResponse Post(string url, IHttpQueryString? queryString, XNode body) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + if (body == null) throw new ArgumentNullException(nameof(body)); + return GetResponse(HttpRequest.Post(url, queryString, body)); + } - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// The options to be used when serializing . - /// An instance of representing the raw response. - public virtual IHttpResponse Post(string url, IHttpQueryString? queryString, XNode body, SaveOptions options) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - if (body == null) throw new ArgumentNullException(nameof(body)); - return GetResponse(HttpRequest.Post(url, queryString, body, options)); - } + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// The options to be used when serializing . + /// An instance of representing the raw response. + public virtual IHttpResponse Post(string url, IHttpQueryString? queryString, XNode body, SaveOptions options) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + if (body == null) throw new ArgumentNullException(nameof(body)); + return GetResponse(HttpRequest.Post(url, queryString, body, options)); + } #if NAME_VALUE_COLLECTION - /// - /// Makes a POST request to the specified . - /// - /// The base URL of the request (no query string). - /// The query string. - /// An instance of representing the raw response. - public virtual IHttpResponse Post(string url, NameValueCollection? queryString) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return GetResponse(HttpRequest.Post(url, query)); - } + /// + /// Makes a POST request to the specified . + /// + /// The base URL of the request (no query string). + /// The query string. + /// An instance of representing the raw response. + public virtual IHttpResponse Post(string url, NameValueCollection? queryString) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return GetResponse(HttpRequest.Post(url, query)); + } - /// - /// Makes a POST request to the specified . - /// - /// The URL of the request. - /// The query string of the request. - /// The body of the request. - /// An instance of representing the response. - public virtual IHttpResponse Post(string url, NameValueCollection? queryString, NameValueCollection? postData) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - IHttpPostData? post = postData == null ? null : new HttpPostData(postData); - return GetResponse(HttpRequest.Post(url, query, post)); - } + /// + /// Makes a POST request to the specified . + /// + /// The URL of the request. + /// The query string of the request. + /// The body of the request. + /// An instance of representing the response. + public virtual IHttpResponse Post(string url, NameValueCollection? queryString, NameValueCollection? postData) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + IHttpPostData? post = postData == null ? null : new HttpPostData(postData); + return GetResponse(HttpRequest.Post(url, query, post)); + } - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The URL of the request. - /// The query string of the request. - /// The content type of the request - eg. application/json. - /// The body of the request. - /// An instance of representing the response. - public virtual IHttpResponse Post(string url, NameValueCollection? queryString, string? contentType, string? body) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return GetResponse(HttpRequest.Post(url, query).SetContentType(contentType).SetBody(body)); - } + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The URL of the request. + /// The query string of the request. + /// The content type of the request - eg. application/json. + /// The body of the request. + /// An instance of representing the response. + public virtual IHttpResponse Post(string url, NameValueCollection? queryString, string? contentType, string? body) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return GetResponse(HttpRequest.Post(url, query).SetContentType(contentType).SetBody(body)); + } - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - public virtual IHttpResponse Post(string url, NameValueCollection? queryString, JToken body) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - if (body == null) throw new ArgumentNullException(nameof(body)); - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return GetResponse(HttpRequest.Post(url, query, body)); - } + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + public virtual IHttpResponse Post(string url, NameValueCollection? queryString, JToken body) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + if (body == null) throw new ArgumentNullException(nameof(body)); + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return GetResponse(HttpRequest.Post(url, query, body)); + } - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// The formatting to be used when serializing . - /// An instance of representing the raw response. - public virtual IHttpResponse Post(string url, NameValueCollection? queryString, JToken body, Formatting formatting) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - if (body == null) throw new ArgumentNullException(nameof(body)); - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return GetResponse(HttpRequest.Post(url, query, body, formatting)); - } + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// The formatting to be used when serializing . + /// An instance of representing the raw response. + public virtual IHttpResponse Post(string url, NameValueCollection? queryString, JToken body, Formatting formatting) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + if (body == null) throw new ArgumentNullException(nameof(body)); + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return GetResponse(HttpRequest.Post(url, query, body, formatting)); + } - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - public virtual IHttpResponse Post(string url, NameValueCollection? queryString, XNode body) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - if (body == null) throw new ArgumentNullException(nameof(body)); - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return GetResponse(HttpRequest.Post(url, query, body)); - } + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + public virtual IHttpResponse Post(string url, NameValueCollection? queryString, XNode body) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + if (body == null) throw new ArgumentNullException(nameof(body)); + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return GetResponse(HttpRequest.Post(url, query, body)); + } - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// The options to be used when serializing . - /// An instance of representing the raw response. - public virtual IHttpResponse Post(string url, NameValueCollection? queryString, XNode body, SaveOptions options) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - if (body == null) throw new ArgumentNullException(nameof(body)); - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return GetResponse(HttpRequest.Post(url, query, body, options)); - } + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// The options to be used when serializing . + /// An instance of representing the raw response. + public virtual IHttpResponse Post(string url, NameValueCollection? queryString, XNode body, SaveOptions options) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + if (body == null) throw new ArgumentNullException(nameof(body)); + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return GetResponse(HttpRequest.Post(url, query, body, options)); + } #endif - } - } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/Client/HttpClient.Put.cs b/src/Skybrud.Essentials.Http/Client/HttpClient.Put.cs index c37a16e..0723049 100644 --- a/src/Skybrud.Essentials.Http/Client/HttpClient.Put.cs +++ b/src/Skybrud.Essentials.Http/Client/HttpClient.Put.cs @@ -6,297 +6,295 @@ using Skybrud.Essentials.Http.Collections; using Skybrud.Essentials.Http.Options; -namespace Skybrud.Essentials.Http.Client { +namespace Skybrud.Essentials.Http.Client; - public partial class HttpClient { +public partial class HttpClient { - /// - /// Makes a PUT request to the specified . - /// - /// The URL of the request. - /// An instance of representing the response. - public virtual IHttpResponse Put(string url) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return GetResponse(HttpRequest.Put(url)); - } + /// + /// Makes a PUT request to the specified . + /// + /// The URL of the request. + /// An instance of representing the response. + public virtual IHttpResponse Put(string url) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return GetResponse(HttpRequest.Put(url)); + } - /// - /// Makes a PUT request to the specified . - /// - /// The URL of the request. - /// The options for the call to the specified . - /// An instance of representing the response. - [Obsolete("Use 'GetResponse' method and 'IHttpRequestOptions' class as parameter instead.")] - public virtual IHttpResponse Put(string url, IHttpGetOptions? options) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return GetResponse(HttpRequest.Put(url, options?.GetQueryString())); - } + /// + /// Makes a PUT request to the specified . + /// + /// The URL of the request. + /// The options for the call to the specified . + /// An instance of representing the response. + [Obsolete("Use 'GetResponse' method and 'IHttpRequestOptions' class as parameter instead.")] + public virtual IHttpResponse Put(string url, IHttpGetOptions? options) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return GetResponse(HttpRequest.Put(url, options?.GetQueryString())); + } - /// - /// Makes a PUT request to the specified . - /// - /// The URL of the request. - /// The options for the call to the specified . - /// An instance of representing the response. - [Obsolete("Use 'GetResponse' method and 'IHttpRequestOptions' class as parameter instead.")] - public virtual IHttpResponse Put(string url, IHttpPostOptions? options) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return GetResponse(HttpRequest.Put(url, options?.GetQueryString(), options?.GetPostData())); - } + /// + /// Makes a PUT request to the specified . + /// + /// The URL of the request. + /// The options for the call to the specified . + /// An instance of representing the response. + [Obsolete("Use 'GetResponse' method and 'IHttpRequestOptions' class as parameter instead.")] + public virtual IHttpResponse Put(string url, IHttpPostOptions? options) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return GetResponse(HttpRequest.Put(url, options?.GetQueryString(), options?.GetPostData())); + } - /// - /// Makes a PUT request to the specified . - /// - /// The base URL of the request (no query string). - /// The query string. - /// An instance of representing the raw response. - public virtual IHttpResponse Put(string url, IHttpQueryString? queryString) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return GetResponse(HttpRequest.Put(url, queryString)); - } + /// + /// Makes a PUT request to the specified . + /// + /// The base URL of the request (no query string). + /// The query string. + /// An instance of representing the raw response. + public virtual IHttpResponse Put(string url, IHttpQueryString? queryString) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return GetResponse(HttpRequest.Put(url, queryString)); + } - /// - /// Makes a PUT request to the specified . - /// - /// The base URL of the request (no query string). - /// The PUT data. - /// An instance of representing the raw response. - public virtual IHttpResponse Put(string url, IHttpPostData? postData) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return GetResponse(HttpRequest.Put(url, postData)); - } + /// + /// Makes a PUT request to the specified . + /// + /// The base URL of the request (no query string). + /// The PUT data. + /// An instance of representing the raw response. + public virtual IHttpResponse Put(string url, IHttpPostData? postData) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return GetResponse(HttpRequest.Put(url, postData)); + } - /// - /// Makes a PUT request to the specified . - /// - /// The URL of the request. - /// The query string of the request. - /// The body of the request. - /// An instance of representing the response. - public virtual IHttpResponse Put(string url, IHttpQueryString? queryString, IHttpPostData postData) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return GetResponse(HttpRequest.Put(url, queryString, postData)); - } + /// + /// Makes a PUT request to the specified . + /// + /// The URL of the request. + /// The query string of the request. + /// The body of the request. + /// An instance of representing the response. + public virtual IHttpResponse Put(string url, IHttpQueryString? queryString, IHttpPostData postData) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return GetResponse(HttpRequest.Put(url, queryString, postData)); + } - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The URL of the request. - /// The query string of the request. - /// The content type of the request - eg. application/json. - /// The body of the request. - /// An instance of representing the response. - public virtual IHttpResponse Put(string url, IHttpQueryString? queryString, string contentType, string body) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return GetResponse(HttpRequest.Put(url, queryString).SetContentType(contentType).SetBody(body)); - } + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The URL of the request. + /// The query string of the request. + /// The content type of the request - eg. application/json. + /// The body of the request. + /// An instance of representing the response. + public virtual IHttpResponse Put(string url, IHttpQueryString? queryString, string contentType, string body) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return GetResponse(HttpRequest.Put(url, queryString).SetContentType(contentType).SetBody(body)); + } - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The body of the request. - /// An instance of representing the raw response. - public virtual IHttpResponse Put(string url, JToken body) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - if (body == null) throw new ArgumentNullException(nameof(body)); - return GetResponse(HttpRequest.Put(url, body)); - } + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The body of the request. + /// An instance of representing the raw response. + public virtual IHttpResponse Put(string url, JToken body) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + if (body == null) throw new ArgumentNullException(nameof(body)); + return GetResponse(HttpRequest.Put(url, body)); + } - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The body of the request. - /// The formatting to be used when serializing . - /// An instance of representing the raw response. - public virtual IHttpResponse Put(string url, JToken body, Formatting formatting) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - if (body == null) throw new ArgumentNullException(nameof(body)); - return GetResponse(HttpRequest.Put(url, body, formatting)); - } + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The body of the request. + /// The formatting to be used when serializing . + /// An instance of representing the raw response. + public virtual IHttpResponse Put(string url, JToken body, Formatting formatting) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + if (body == null) throw new ArgumentNullException(nameof(body)); + return GetResponse(HttpRequest.Put(url, body, formatting)); + } - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - public virtual IHttpResponse Put(string url, IHttpQueryString? queryString, JToken body) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - if (body == null) throw new ArgumentNullException(nameof(body)); - return GetResponse(HttpRequest.Put(url, queryString, body)); - } + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + public virtual IHttpResponse Put(string url, IHttpQueryString? queryString, JToken body) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + if (body == null) throw new ArgumentNullException(nameof(body)); + return GetResponse(HttpRequest.Put(url, queryString, body)); + } - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// The formatting to be used when serializing . - /// An instance of representing the raw response. - public virtual IHttpResponse Put(string url, IHttpQueryString? queryString, JToken body, Formatting formatting) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - if (body == null) throw new ArgumentNullException(nameof(body)); - return GetResponse(HttpRequest.Put(url, queryString, body, formatting)); - } + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// The formatting to be used when serializing . + /// An instance of representing the raw response. + public virtual IHttpResponse Put(string url, IHttpQueryString? queryString, JToken body, Formatting formatting) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + if (body == null) throw new ArgumentNullException(nameof(body)); + return GetResponse(HttpRequest.Put(url, queryString, body, formatting)); + } - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The body of the request. - /// An instance of representing the raw response. - public virtual IHttpResponse Put(string url, XNode body) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - if (body == null) throw new ArgumentNullException(nameof(body)); - return GetResponse(HttpRequest.Put(url, body)); - } + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The body of the request. + /// An instance of representing the raw response. + public virtual IHttpResponse Put(string url, XNode body) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + if (body == null) throw new ArgumentNullException(nameof(body)); + return GetResponse(HttpRequest.Put(url, body)); + } - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The body of the request. - /// The options to be used when serializing . - /// An instance of representing the raw response. - public virtual IHttpResponse Put(string url, XNode body, SaveOptions options) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - if (body == null) throw new ArgumentNullException(nameof(body)); - return GetResponse(HttpRequest.Put(url, body, options)); - } + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The body of the request. + /// The options to be used when serializing . + /// An instance of representing the raw response. + public virtual IHttpResponse Put(string url, XNode body, SaveOptions options) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + if (body == null) throw new ArgumentNullException(nameof(body)); + return GetResponse(HttpRequest.Put(url, body, options)); + } - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - public virtual IHttpResponse Put(string url, IHttpQueryString? queryString, XNode body) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - if (body == null) throw new ArgumentNullException(nameof(body)); - return GetResponse(HttpRequest.Put(url, queryString, body)); - } + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + public virtual IHttpResponse Put(string url, IHttpQueryString? queryString, XNode body) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + if (body == null) throw new ArgumentNullException(nameof(body)); + return GetResponse(HttpRequest.Put(url, queryString, body)); + } - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// The options to be used when serializing . - /// An instance of representing the raw response. - public virtual IHttpResponse Put(string url, IHttpQueryString? queryString, XNode body, SaveOptions options) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - if (body == null) throw new ArgumentNullException(nameof(body)); - return GetResponse(HttpRequest.Put(url, queryString, body, options)); - } + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// The options to be used when serializing . + /// An instance of representing the raw response. + public virtual IHttpResponse Put(string url, IHttpQueryString? queryString, XNode body, SaveOptions options) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + if (body == null) throw new ArgumentNullException(nameof(body)); + return GetResponse(HttpRequest.Put(url, queryString, body, options)); + } #if NAME_VALUE_COLLECTION - /// - /// Makes a PUT request to the specified . - /// - /// The base URL of the request (no query string). - /// The query string. - /// An instance of representing the raw response. - public virtual IHttpResponse Put(string url, NameValueCollection? queryString) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return GetResponse(HttpRequest.Put(url, query)); - } + /// + /// Makes a PUT request to the specified . + /// + /// The base URL of the request (no query string). + /// The query string. + /// An instance of representing the raw response. + public virtual IHttpResponse Put(string url, NameValueCollection? queryString) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return GetResponse(HttpRequest.Put(url, query)); + } - /// - /// Makes a PUT request to the specified . - /// - /// The URL of the request. - /// The query string of the request. - /// The body of the request. - /// An instance of representing the response. - public virtual IHttpResponse Put(string url, NameValueCollection? queryString, NameValueCollection? postData) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - IHttpPostData? post = postData == null ? null : new HttpPostData(postData); - return GetResponse(HttpRequest.Put(url, query, post)); - } + /// + /// Makes a PUT request to the specified . + /// + /// The URL of the request. + /// The query string of the request. + /// The body of the request. + /// An instance of representing the response. + public virtual IHttpResponse Put(string url, NameValueCollection? queryString, NameValueCollection? postData) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + IHttpPostData? post = postData == null ? null : new HttpPostData(postData); + return GetResponse(HttpRequest.Put(url, query, post)); + } - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The URL of the request. - /// The query string of the request. - /// The content type of the request - eg. application/json. - /// The body of the request. - /// An instance of representing the response. - public virtual IHttpResponse Put(string url, NameValueCollection? queryString, string contentType, string body) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return GetResponse(HttpRequest.Put(url, query).SetContentType(contentType).SetBody(body)); - } + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The URL of the request. + /// The query string of the request. + /// The content type of the request - eg. application/json. + /// The body of the request. + /// An instance of representing the response. + public virtual IHttpResponse Put(string url, NameValueCollection? queryString, string contentType, string body) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return GetResponse(HttpRequest.Put(url, query).SetContentType(contentType).SetBody(body)); + } - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - public virtual IHttpResponse Put(string url, NameValueCollection? queryString, JToken body) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - if (body == null) throw new ArgumentNullException(nameof(body)); - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return GetResponse(HttpRequest.Put(url, query, body)); - } + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + public virtual IHttpResponse Put(string url, NameValueCollection? queryString, JToken body) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + if (body == null) throw new ArgumentNullException(nameof(body)); + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return GetResponse(HttpRequest.Put(url, query, body)); + } - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// The formatting to be used when serializing . - /// An instance of representing the raw response. - public virtual IHttpResponse Put(string url, NameValueCollection? queryString, JToken body, Formatting formatting) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - if (body == null) throw new ArgumentNullException(nameof(body)); - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return GetResponse(HttpRequest.Put(url, query, body, formatting)); - } + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// The formatting to be used when serializing . + /// An instance of representing the raw response. + public virtual IHttpResponse Put(string url, NameValueCollection? queryString, JToken body, Formatting formatting) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + if (body == null) throw new ArgumentNullException(nameof(body)); + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return GetResponse(HttpRequest.Put(url, query, body, formatting)); + } - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - public virtual IHttpResponse Put(string url, NameValueCollection? queryString, XNode body) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - if (body == null) throw new ArgumentNullException(nameof(body)); - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return GetResponse(HttpRequest.Put(url, query, body)); - } + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + public virtual IHttpResponse Put(string url, NameValueCollection? queryString, XNode body) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + if (body == null) throw new ArgumentNullException(nameof(body)); + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return GetResponse(HttpRequest.Put(url, query, body)); + } - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// The options to be used when serializing . - /// An instance of representing the raw response. - public virtual IHttpResponse Put(string url, NameValueCollection? queryString, XNode body, SaveOptions options) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - if (body == null) throw new ArgumentNullException(nameof(body)); - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return GetResponse(HttpRequest.Put(url, query, body, options)); - } + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// The options to be used when serializing . + /// An instance of representing the raw response. + public virtual IHttpResponse Put(string url, NameValueCollection? queryString, XNode body, SaveOptions options) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + if (body == null) throw new ArgumentNullException(nameof(body)); + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return GetResponse(HttpRequest.Put(url, query, body, options)); + } #endif - } - } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/Client/HttpClient.cs b/src/Skybrud.Essentials.Http/Client/HttpClient.cs index f113755..7ed08e3 100644 --- a/src/Skybrud.Essentials.Http/Client/HttpClient.cs +++ b/src/Skybrud.Essentials.Http/Client/HttpClient.cs @@ -5,955 +5,954 @@ using Skybrud.Essentials.Http.Collections; using Skybrud.Essentials.Http.Options; using System.Threading.Tasks; + // ReSharper disable ArrangeDefaultValueWhenTypeNotEvident -namespace Skybrud.Essentials.Http.Client { - - /// - /// Class representing a client for making HTTP requests. - /// - public partial class HttpClient : IHttpClient, IHttpClientAsync { - - #region DoHttpGetRequest - - /// - /// Makes a HTTP GET request to the specified . - /// - /// The URL of the request. - /// An instance of representing the response. - [Obsolete("Use the Get method instead.")] - public virtual IHttpResponse DoHttpGetRequest(string url) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return DoHttpRequest(HttpMethod.Get, url, default(IHttpQueryString)); - } - - /// - /// Makes a GET request to the specified . - /// - /// The URL of the request. - /// The options for the call to the specified . - /// An instance of representing the response. - [Obsolete("Use the Get method instead.")] - public virtual IHttpResponse DoHttpGetRequest(string url, IHttpGetOptions options) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - if (options == null) throw new ArgumentNullException(nameof(options)); - return DoHttpRequest(HttpMethod.Get, url, options.GetQueryString()); - } - - /// - /// Makes a GET request to the specified . - /// - /// The URL of the request. - /// The query string of the request. - /// An instance of representing the response. - [Obsolete("Use the Get method instead.")] - public virtual IHttpResponse DoHttpGetRequest(string url, IHttpQueryString queryString) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return DoHttpRequest(HttpMethod.Get, url, queryString); - } - - #endregion - - #region DoHttpPostRequest - - /// - /// Makes a POST request to the specified . - /// - /// The URL of the request. - /// An instance of representing the response. - [Obsolete("Use the Post method instead.")] - public virtual IHttpResponse DoHttpPostRequest(string url) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return DoHttpRequest(HttpMethod.Post, url, default(IHttpQueryString), default(IHttpPostData)); - } - - /// - /// Makes a POST request to the specified . - /// - /// The URL of the request. - /// The options for the call to the specified . - /// An instance of representing the response. - [Obsolete("Use the Post method instead.")] - public virtual IHttpResponse DoHttpPostRequest(string url, IHttpGetOptions options) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - if (options == null) throw new ArgumentNullException(nameof(options)); - return DoHttpRequest(HttpMethod.Post, url, options.GetQueryString(), default(IHttpPostData)); - } - - /// - /// Makes a POST request to the specified . - /// - /// The URL of the request. - /// The options for the call to the specified . - /// An instance of representing the response. - [Obsolete("Use the Post method instead.")] - public virtual IHttpResponse DoHttpPostRequest(string url, IHttpPostOptions options) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - if (options == null) throw new ArgumentNullException(nameof(options)); - return DoHttpRequest(HttpMethod.Post, url, options.GetQueryString(), options.GetPostData()); - } - - /// - /// Makes a POST request to the specified . - /// - /// The base URL of the request (no query string). - /// The query string. - /// An instance of representing the raw response. - [Obsolete("Use the Post method instead.")] - public virtual IHttpResponse DoHttpPostRequest(string url, IHttpQueryString queryString) { - return DoHttpRequest(HttpMethod.Post, url, queryString, default(IHttpPostData)); - } - - /// - /// Makes a POST request to the specified . - /// - /// The base URL of the request (no query string). - /// The POST data. - /// An instance of representing the raw response. - [Obsolete("Use the Post method instead.")] - public virtual IHttpResponse DoHttpPostRequest(string url, IHttpPostData postData) { - return DoHttpRequest(HttpMethod.Post, url, null, postData); - } - - /// - /// Makes a POST request to the specified . - /// - /// The URL of the request. - /// The query string of the request. - /// The POST data of the request. - /// An instance of representing the response. - [Obsolete("Use the Post method instead.")] - public virtual IHttpResponse DoHttpPostRequest(string url, IHttpQueryString queryString, IHttpPostData postData) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return DoHttpRequest(HttpMethod.Post, url, queryString, postData); - } - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The URL of the request. - /// The query string of the request. - /// The content type of the request - eg. application/json. - /// The body of the request. - /// An instance of representing the response. - [Obsolete("Use the Post method instead.")] - public virtual IHttpResponse DoHttpPostRequest(string url, IHttpQueryString queryString, string contentType, string body) { - return DoHttpRequest(HttpMethod.Post, url, queryString, contentType, body); - } - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The body of the request. - /// An instance of representing the raw response. - [Obsolete("Use the Post method instead.")] - public virtual IHttpResponse DoHttpPostRequest(string url, JToken body) { - if (body == null) throw new ArgumentNullException(nameof(body)); - return DoHttpRequest(HttpMethod.Post, url, default(IHttpQueryString), body); - } - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The body of the request. - /// The formatting to be used when serializing . - /// An instance of representing the raw response. - [Obsolete("Use the Post method instead.")] - public virtual IHttpResponse DoHttpPostRequest(string url, JToken body, Formatting formatting) { - if (body == null) throw new ArgumentNullException(nameof(body)); - return DoHttpRequest(HttpMethod.Post, url, default(IHttpQueryString), body); - } - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - [Obsolete("Use the Post method instead.")] - public virtual IHttpResponse DoHttpPostRequest(string url, IHttpQueryString queryString, JToken body) { - if (body == null) throw new ArgumentNullException(nameof(body)); - return DoHttpRequest(HttpMethod.Post, url, queryString, body); - } - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// The formatting to be used when serializing . - /// An instance of representing the raw response. - [Obsolete("Use the Post method instead.")] - public virtual IHttpResponse DoHttpPostRequest(string url, IHttpQueryString queryString, JToken body, Formatting formatting) { - if (body == null) throw new ArgumentNullException(nameof(body)); - return DoHttpRequest(HttpMethod.Post, url, queryString, body); - } - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The body of the request. - /// An instance of representing the raw response. - [Obsolete("Use the Post method instead.")] - public virtual IHttpResponse DoHttpPostRequest(string url, XNode body) { - if (body == null) throw new ArgumentNullException(nameof(body)); - return DoHttpRequest(HttpMethod.Post, url, default(IHttpQueryString), body); - } - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The body of the request. - /// The options to be used when serializing . - /// An instance of representing the raw response. - [Obsolete("Use the Post method instead.")] - public virtual IHttpResponse DoHttpPostRequest(string url, XNode body, SaveOptions options) { - if (body == null) throw new ArgumentNullException(nameof(body)); - return DoHttpRequest(HttpMethod.Post, url, default(IHttpQueryString), body); - } - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - [Obsolete("Use the Post method instead.")] - public virtual IHttpResponse DoHttpPostRequest(string url, IHttpQueryString queryString, XNode body) { - if (body == null) throw new ArgumentNullException(nameof(body)); - return DoHttpRequest(HttpMethod.Post, url, queryString, body); - } - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// The options to be used when serializing . - /// An instance of representing the raw response. - [Obsolete("Use the Post method instead.")] - public virtual IHttpResponse DoHttpPostRequest(string url, IHttpQueryString queryString, XNode body, SaveOptions options) { - if (body == null) throw new ArgumentNullException(nameof(body)); - return DoHttpRequest(HttpMethod.Post, url, queryString, body, options); - } - - #endregion - - #region DoHttpPutRequest - - /// - /// Makes a PUT request to the specified . - /// - /// The URL of the request. - /// An instance of representing the response. - [Obsolete("Use the Put method instead.")] - public virtual IHttpResponse DoHttpPutRequest(string url) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return DoHttpRequest(HttpMethod.Put, url, default(IHttpQueryString), default(IHttpPostData)); - } - - /// - /// Makes a PUT request to the specified . - /// - /// The URL of the request. - /// The options for the call to the specified . - /// An instance of representing the response. - [Obsolete("Use the Put method instead.")] - public virtual IHttpResponse DoHttpPutRequest(string url, IHttpGetOptions options) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - if (options == null) throw new ArgumentNullException(nameof(options)); - return DoHttpRequest(HttpMethod.Put, url, options.GetQueryString(), default(IHttpPostData)); - } - - /// - /// Makes a PUT request to the specified . - /// - /// The URL of the request. - /// The options for the call to the specified . - /// An instance of representing the response. - [Obsolete("Use the Put method instead.")] - public virtual IHttpResponse DoHttpPutRequest(string url, IHttpPostOptions options) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - if (options == null) throw new ArgumentNullException(nameof(options)); - return DoHttpRequest(HttpMethod.Put, url, options.GetQueryString(), options.GetPostData()); - } - - /// - /// Makes a PUT request to the specified . - /// - /// The base URL of the request (no query string). - /// The query string. - /// An instance of representing the raw response. - [Obsolete("Use the Put method instead.")] - public virtual IHttpResponse DoHttpPutRequest(string url, IHttpQueryString queryString) { - return DoHttpRequest(HttpMethod.Put, url, queryString, default(IHttpPostData)); - } - - /// - /// Makes a PUT request to the specified . - /// - /// The base URL of the request (no query string). - /// The POST data. - /// An instance of representing the raw response. - [Obsolete("Use the Put method instead.")] - public virtual IHttpResponse DoHttpPutRequest(string url, IHttpPostData postData) { - return DoHttpRequest(HttpMethod.Put, url, null, postData); - } - - /// - /// Makes a PUT request to the specified . - /// - /// The URL of the request. - /// The query string of the request. - /// The POST data of the request. - /// An instance of representing the response. - [Obsolete("Use the Put method instead.")] - public virtual IHttpResponse DoHttpPutRequest(string url, IHttpQueryString queryString, IHttpPostData postData) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return DoHttpRequest(HttpMethod.Put, url, queryString, postData); - } - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The URL of the request. - /// The query string of the request. - /// The content type of the request - eg. application/json. - /// The body of the request. - /// An instance of representing the response. - [Obsolete("Use the Put method instead.")] - public virtual IHttpResponse DoHttpPutRequest(string url, IHttpQueryString queryString, string contentType, string body) { - return DoHttpRequest(HttpMethod.Put, url, queryString, contentType, body); - } - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The body of the request. - /// An instance of representing the raw response. - [Obsolete("Use the Put method instead.")] - public virtual IHttpResponse DoHttpPutRequest(string url, JToken body) { - if (body == null) throw new ArgumentNullException(nameof(body)); - return DoHttpRequest(HttpMethod.Put, url, default(IHttpQueryString), body); - } - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The body of the request. - /// The formatting to be used when serializing . - /// An instance of representing the raw response. - [Obsolete("Use the Put method instead.")] - public virtual IHttpResponse DoHttpPutRequest(string url, JToken body, Formatting formatting) { - if (body == null) throw new ArgumentNullException(nameof(body)); - return DoHttpRequest(HttpMethod.Put, url, default(IHttpQueryString), body); - } - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - [Obsolete("Use the Put method instead.")] - public virtual IHttpResponse DoHttpPutRequest(string url, IHttpQueryString queryString, JToken body) { - if (body == null) throw new ArgumentNullException(nameof(body)); - return DoHttpRequest(HttpMethod.Put, url, queryString, body); - } - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// The formatting to be used when serializing . - /// An instance of representing the raw response. - [Obsolete("Use the Put method instead.")] - public virtual IHttpResponse DoHttpPutRequest(string url, IHttpQueryString queryString, JToken body, Formatting formatting) { - if (body == null) throw new ArgumentNullException(nameof(body)); - return DoHttpRequest(HttpMethod.Put, url, queryString, body); - } - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The body of the request. - /// An instance of representing the raw response. - [Obsolete("Use the Put method instead.")] - public virtual IHttpResponse DoHttpPutRequest(string url, XNode body) { - if (body == null) throw new ArgumentNullException(nameof(body)); - return DoHttpRequest(HttpMethod.Put, url, default(IHttpQueryString), body); - } - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The body of the request. - /// The options to be used when serializing . - /// An instance of representing the raw response. - [Obsolete("Use the Put method instead.")] - public virtual IHttpResponse DoHttpPutRequest(string url, XNode body, SaveOptions options) { - if (body == null) throw new ArgumentNullException(nameof(body)); - return DoHttpRequest(HttpMethod.Put, url, default(IHttpQueryString), body); - } - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - [Obsolete("Use the Put method instead.")] - public virtual IHttpResponse DoHttpPutRequest(string url, IHttpQueryString queryString, XNode body) { - if (body == null) throw new ArgumentNullException(nameof(body)); - return DoHttpRequest(HttpMethod.Put, url, queryString, body); - } - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// The options to be used when serializing . - /// An instance of representing the raw response. - [Obsolete("Use the Put method instead.")] - public virtual IHttpResponse DoHttpPutRequest(string url, IHttpQueryString queryString, XNode body, SaveOptions options) { - if (body == null) throw new ArgumentNullException(nameof(body)); - return DoHttpRequest(HttpMethod.Put, url, queryString, body, options); - } - - #endregion - - #region DoHttpPatchRequest - - /// - /// Makes a PATCH request to the specified . - /// - /// The URL of the request. - /// An instance of representing the response. - [Obsolete("Use the Patch method instead.")] - public virtual IHttpResponse DoHttpPatchRequest(string url) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return DoHttpRequest(HttpMethod.Patch, url, default(IHttpQueryString), default(IHttpPostData)); - } - - /// - /// Makes a PATCH request to the specified . - /// - /// The URL of the request. - /// The options for the call to the specified . - /// An instance of representing the response. - [Obsolete("Use the Patch method instead.")] - public virtual IHttpResponse DoHttpPatchRequest(string url, IHttpGetOptions options) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - if (options == null) throw new ArgumentNullException(nameof(options)); - return DoHttpRequest(HttpMethod.Patch, url, options.GetQueryString(), default(IHttpPostData)); - } - - /// - /// Makes a PATCH request to the specified . - /// - /// The URL of the request. - /// The options for the call to the specified . - /// An instance of representing the response. - [Obsolete("Use the Patch method instead.")] - public virtual IHttpResponse DoHttpPatchRequest(string url, IHttpPostOptions options) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - if (options == null) throw new ArgumentNullException(nameof(options)); - return DoHttpRequest(HttpMethod.Patch, url, options.GetQueryString(), options.GetPostData()); - } - - /// - /// Makes a PATCH request to the specified . - /// - /// The base URL of the request (no query string). - /// The query string. - /// An instance of representing the raw response. - [Obsolete("Use the Patch method instead.")] - public virtual IHttpResponse DoHttpPatchRequest(string url, IHttpQueryString queryString) { - return DoHttpRequest(HttpMethod.Patch, url, queryString, default(IHttpPostData)); - } - - /// - /// Makes a PATCH request to the specified . - /// - /// The base URL of the request (no query string). - /// The POST data. - /// An instance of representing the raw response. - [Obsolete("Use the Patch method instead.")] - public virtual IHttpResponse DoHttpPatchRequest(string url, IHttpPostData postData) { - return DoHttpRequest(HttpMethod.Patch, url, null, postData); - } - - /// - /// Makes a PATCH request to the specified . - /// - /// The URL of the request. - /// The query string of the request. - /// The POST data of the request. - /// An instance of representing the response. - [Obsolete("Use the Patch method instead.")] - public virtual IHttpResponse DoHttpPatchRequest(string url, IHttpQueryString queryString, IHttpPostData postData) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return DoHttpRequest(HttpMethod.Patch, url, queryString, postData); - } - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The URL of the request. - /// The query string of the request. - /// The content type of the request - eg. application/json. - /// The body of the request. - /// An instance of representing the response. - [Obsolete("Use the Patch method instead.")] - public virtual IHttpResponse DoHttpPatchRequest(string url, IHttpQueryString queryString, string contentType, string body) { - return DoHttpRequest(HttpMethod.Patch, url, queryString, contentType, body); - } - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The body of the request. - /// An instance of representing the raw response. - [Obsolete("Use the Patch method instead.")] - public virtual IHttpResponse DoHttpPatchRequest(string url, JToken body) { - if (body == null) throw new ArgumentNullException(nameof(body)); - return DoHttpRequest(HttpMethod.Patch, url, default(IHttpQueryString), body); - } - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The body of the request. - /// The formatting to be used when serializing . - /// An instance of representing the raw response. - [Obsolete("Use the Patch method instead.")] - public virtual IHttpResponse DoHttpPatchRequest(string url, JToken body, Formatting formatting) { - if (body == null) throw new ArgumentNullException(nameof(body)); - return DoHttpRequest(HttpMethod.Patch, url, default(IHttpQueryString), body); - } - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - [Obsolete("Use the Patch method instead.")] - public virtual IHttpResponse DoHttpPatchRequest(string url, IHttpQueryString queryString, JToken body) { - if (body == null) throw new ArgumentNullException(nameof(body)); - return DoHttpRequest(HttpMethod.Patch, url, queryString, body); - } - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// The formatting to be used when serializing . - /// An instance of representing the raw response. - [Obsolete("Use the Patch method instead.")] - public virtual IHttpResponse DoHttpPatchRequest(string url, IHttpQueryString queryString, JToken body, Formatting formatting) { - if (body == null) throw new ArgumentNullException(nameof(body)); - return DoHttpRequest(HttpMethod.Patch, url, queryString, body); - } - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The body of the request. - /// An instance of representing the raw response. - [Obsolete("Use the Patch method instead.")] - public virtual IHttpResponse DoHttpPatchRequest(string url, XNode body) { - if (body == null) throw new ArgumentNullException(nameof(body)); - return DoHttpRequest(HttpMethod.Patch, url, default(IHttpQueryString), body); - } - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The body of the request. - /// The options to be used when serializing . - /// An instance of representing the raw response. - [Obsolete("Use the Patch method instead.")] - public virtual IHttpResponse DoHttpPatchRequest(string url, XNode body, SaveOptions options) { - if (body == null) throw new ArgumentNullException(nameof(body)); - return DoHttpRequest(HttpMethod.Patch, url, default(IHttpQueryString), body); - } - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - [Obsolete("Use the Patch method instead.")] - public virtual IHttpResponse DoHttpPatchRequest(string url, IHttpQueryString? queryString, XNode body) { - if (body == null) throw new ArgumentNullException(nameof(body)); - return DoHttpRequest(HttpMethod.Patch, url, queryString, body); - } - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// The options to be used when serializing . - /// An instance of representing the raw response. - [Obsolete("Use the Patch method instead.")] - public virtual IHttpResponse DoHttpPatchRequest(string url, IHttpQueryString? queryString, XNode body, SaveOptions options) { - if (body == null) throw new ArgumentNullException(nameof(body)); - return DoHttpRequest(HttpMethod.Patch, url, queryString, body, options); - } - - #endregion - - #region DoHttpDeleteRequest - - /// - /// Makes a HTTP DELETE request to the specified . - /// - /// The URL of the request. - /// An instance of representing the response. - [Obsolete("Use the Delete method instead.")] - public virtual IHttpResponse DoHttpDeleteRequest(string url) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return DoHttpRequest(HttpMethod.Delete, url, default(IHttpQueryString)); - } - - /// - /// Makes a DELETE request to the specified . - /// - /// The URL of the request. - /// The options for the call to the specified . - /// An instance of representing the response. - [Obsolete("Use the Delete method instead.")] - public virtual IHttpResponse DoHttpDeleteRequest(string url, IHttpGetOptions options) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - if (options == null) throw new ArgumentNullException(nameof(options)); - return DoHttpRequest(HttpMethod.Delete, url, options.GetQueryString()); - } - - /// - /// Makes a DELETE request to the specified . - /// - /// The URL of the request. - /// The query string of the request. - /// An instance of representing the response. - [Obsolete("Use the Delete method instead.")] - public virtual IHttpResponse DoHttpDeleteRequest(string url, IHttpQueryString? queryString) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return DoHttpRequest(HttpMethod.Delete, url, queryString); - } - - #endregion - - #region DoHttpRequest - - /// - /// Makes a HTTP request to the underlying API based on the specified parameters. - /// - /// The HTTP method of the request. - /// The base URL of the request (no query string). - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - public virtual IHttpResponse DoHttpRequest(HttpMethod method, string url) { - return DoHttpRequest(method, url, default(IHttpQueryString), default(IHttpPostData)); - } - - /// - /// Makes a HTTP request to the underlying API based on the specified parameters. - /// - /// The HTTP method of the request. - /// The base URL of the request (no query string). - /// The options for the call to the API. - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - public virtual IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpGetOptions options) { - if (options == null) throw new ArgumentNullException(nameof(options)); - return DoHttpRequest(method, url, options.GetQueryString()); - } - - /// - /// Makes a HTTP request to the underlying API based on the specified parameters. - /// - /// The HTTP method of the request. - /// The base URL of the request (no query string). - /// The query string. - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - public virtual IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpQueryString? queryString) { - return DoHttpRequest(method, url, queryString, default(IHttpPostData)); - } - - /// - /// Makes a HTTP request to the underlying API based on the specified parameters. - /// - /// The HTTP method of the request. - /// The base URL of the request (no query string). - /// The POST data. - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - public virtual IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpPostData? postData) { - return DoHttpRequest(method, url, null, postData); - } - - /// - /// Makes a HTTP request to the underlying API based on the specified parameters. - /// - /// The HTTP method of the request. - /// The base URL of the request (no query string). - /// The query string. - /// The POST data. - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - public virtual IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpQueryString? queryString, IHttpPostData? postData) { - - // Some input validation - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - - // Initialize the request - HttpRequest request = new() { - Method = method, - Url = url, - QueryString = queryString!, - PostData = postData! - }; - - PrepareHttpRequest(request); - - // Make the call to the URL - return request.GetResponse(); - - } - - /// - /// Makes a HTTP request to the underlying API based on the specified parameters. - /// - /// The HTTP method of the request. - /// The base URL of the request (no query string). - /// The query string. - /// The content type of the request - eg. application/json. - /// The body of the request. - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - public virtual IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpQueryString? queryString, string? contentType, string? body) { - - // Some input validation - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - - // Initialize the request - HttpRequest request = new() { - Method = method, - Url = url, - QueryString = queryString!, - ContentType = contentType, - Body = body - }; - - PrepareHttpRequest(request); - - // Make the call to the URL - return request.GetResponse(); - - } - - /// - /// Makes a HTTP request based on the specified parameters. - /// - /// The HTTP method of the request. - /// The base URL of the request (no query string). - /// The body of the request. - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - public virtual IHttpResponse DoHttpRequest(HttpMethod method, string url, JToken body) { - if (body == null) throw new ArgumentNullException(nameof(body)); - return DoHttpRequest(method, url, default(IHttpQueryString), HttpConstants.ApplicationJson, body.ToString(Formatting.None)); - } - - /// - /// Makes a HTTP request based on the specified parameters. - /// - /// The HTTP method of the request. - /// The base URL of the request (no query string). - /// The body of the request. - /// The formatting to be used when serializing . - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - public virtual IHttpResponse DoHttpRequest(HttpMethod method, string url, JToken body, Formatting formatting) { - if (body == null) throw new ArgumentNullException(nameof(body)); - return DoHttpRequest(method, url, default(IHttpQueryString), HttpConstants.ApplicationJson, body.ToString(formatting)); - } - - /// - /// Makes a HTTP request based on the specified parameters. - /// - /// The HTTP method of the request. - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - public virtual IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpQueryString? queryString, JToken body) { - if (body == null) throw new ArgumentNullException(nameof(body)); - return DoHttpRequest(method, url, queryString, HttpConstants.ApplicationJson, body.ToString(Formatting.None)); - } - - /// - /// Makes a HTTP request based on the specified parameters. - /// - /// The HTTP method of the request. - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// The formatting to be used when serializing . - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - public virtual IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpQueryString? queryString, JToken body, Formatting formatting) { - if (body == null) throw new ArgumentNullException(nameof(body)); - return DoHttpRequest(method, url, queryString, HttpConstants.ApplicationJson, body.ToString(formatting)); - } - - /// - /// Makes a HTTP request based on the specified parameters. - /// - /// The HTTP method of the request. - /// The base URL of the request (no query string). - /// The body of the request. - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - public virtual IHttpResponse DoHttpRequest(HttpMethod method, string url, XNode body) { - if (body == null) throw new ArgumentNullException(nameof(body)); - return DoHttpRequest(method, url, default(IHttpQueryString), HttpConstants.TextXml, body.ToString(SaveOptions.None)); - } - - /// - /// Makes a HTTP request based on the specified parameters. - /// - /// The HTTP method of the request. - /// The base URL of the request (no query string). - /// The body of the request. - /// The options to be used when serializing . - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - public virtual IHttpResponse DoHttpRequest(HttpMethod method, string url, XNode body, SaveOptions options) { - if (body == null) throw new ArgumentNullException(nameof(body)); - return DoHttpRequest(method, url, default(IHttpQueryString), HttpConstants.TextXml, body.ToString(options)); - } - - /// - /// Makes a HTTP request based on the specified parameters. - /// - /// The HTTP method of the request. - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - public virtual IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpQueryString? queryString, XNode body) { - if (body == null) throw new ArgumentNullException(nameof(body)); - return DoHttpRequest(method, url, queryString, HttpConstants.TextXml, body.ToString(SaveOptions.None)); - } - - /// - /// Makes a HTTP request based on the specified parameters. - /// - /// The HTTP method of the request. - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// The options to be used when serializing . - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - public virtual IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpQueryString? queryString, XNode body, SaveOptions options) { - if (body == null) throw new ArgumentNullException(nameof(body)); - return DoHttpRequest(method, url, queryString, HttpConstants.TextXml, body.ToString(options)); - } - - #endregion - - #region Other - - /// - /// Returns the response of the request identified by the specified . - /// - /// The options for the request to the API. - /// An instance of representing the raw response. - public virtual IHttpResponse GetResponse(IHttpRequestOptions options) { - if (options == null) throw new ArgumentNullException(nameof(options)); - IHttpRequest request = options.GetRequest(); - PrepareHttpRequest(request); - return request.GetResponse(); - } - - /// - /// Sends a new request as described by and returns the response. - /// - /// An instance of describing the request. - /// An instance of representing the raw response. - public virtual IHttpResponse GetResponse(IHttpRequest request) { - if (request == null) throw new ArgumentNullException(nameof(request)); - PrepareHttpRequest(request); - return request.GetResponse(); - } - - /// - /// Executes a new the request described by the specified and returns the - /// response as an instance of . - /// - /// An instance of representing the response. - public async Task GetResponseAsync(IHttpRequestOptions options) { - if (options == null) throw new ArgumentNullException(nameof(options)); - IHttpRequest request = options.GetRequest(); - PrepareHttpRequest(request); - return await request.GetResponseAsync(); - } - - /// - /// Executes the specified and returns the response as an instance of - /// . - /// - /// An instance of describing the request. - /// An instance of representing the raw response. - public virtual async Task GetResponseAsync(IHttpRequest request) { - if (request == null) throw new ArgumentNullException(nameof(request)); - PrepareHttpRequest(request); - return await request.GetResponseAsync(); - } - - /// - /// Virtual method that can be used for configuring a request. - /// - /// The request. - protected virtual void PrepareHttpRequest(IHttpRequest request) { } - - #endregion +namespace Skybrud.Essentials.Http.Client; + +/// +/// Class representing a client for making HTTP requests. +/// +public partial class HttpClient : IHttpClient, IHttpClientAsync { + + #region DoHttpGetRequest + + /// + /// Makes a HTTP GET request to the specified . + /// + /// The URL of the request. + /// An instance of representing the response. + [Obsolete("Use the Get method instead.")] + public virtual IHttpResponse DoHttpGetRequest(string url) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return DoHttpRequest(HttpMethod.Get, url, default(IHttpQueryString)); + } + + /// + /// Makes a GET request to the specified . + /// + /// The URL of the request. + /// The options for the call to the specified . + /// An instance of representing the response. + [Obsolete("Use the Get method instead.")] + public virtual IHttpResponse DoHttpGetRequest(string url, IHttpGetOptions options) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + if (options == null) throw new ArgumentNullException(nameof(options)); + return DoHttpRequest(HttpMethod.Get, url, options.GetQueryString()); + } + + /// + /// Makes a GET request to the specified . + /// + /// The URL of the request. + /// The query string of the request. + /// An instance of representing the response. + [Obsolete("Use the Get method instead.")] + public virtual IHttpResponse DoHttpGetRequest(string url, IHttpQueryString queryString) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return DoHttpRequest(HttpMethod.Get, url, queryString); + } + + #endregion + + #region DoHttpPostRequest + + /// + /// Makes a POST request to the specified . + /// + /// The URL of the request. + /// An instance of representing the response. + [Obsolete("Use the Post method instead.")] + public virtual IHttpResponse DoHttpPostRequest(string url) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return DoHttpRequest(HttpMethod.Post, url, default(IHttpQueryString), default(IHttpPostData)); + } + + /// + /// Makes a POST request to the specified . + /// + /// The URL of the request. + /// The options for the call to the specified . + /// An instance of representing the response. + [Obsolete("Use the Post method instead.")] + public virtual IHttpResponse DoHttpPostRequest(string url, IHttpGetOptions options) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + if (options == null) throw new ArgumentNullException(nameof(options)); + return DoHttpRequest(HttpMethod.Post, url, options.GetQueryString(), default(IHttpPostData)); + } + + /// + /// Makes a POST request to the specified . + /// + /// The URL of the request. + /// The options for the call to the specified . + /// An instance of representing the response. + [Obsolete("Use the Post method instead.")] + public virtual IHttpResponse DoHttpPostRequest(string url, IHttpPostOptions options) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + if (options == null) throw new ArgumentNullException(nameof(options)); + return DoHttpRequest(HttpMethod.Post, url, options.GetQueryString(), options.GetPostData()); + } + + /// + /// Makes a POST request to the specified . + /// + /// The base URL of the request (no query string). + /// The query string. + /// An instance of representing the raw response. + [Obsolete("Use the Post method instead.")] + public virtual IHttpResponse DoHttpPostRequest(string url, IHttpQueryString queryString) { + return DoHttpRequest(HttpMethod.Post, url, queryString, default(IHttpPostData)); + } + + /// + /// Makes a POST request to the specified . + /// + /// The base URL of the request (no query string). + /// The POST data. + /// An instance of representing the raw response. + [Obsolete("Use the Post method instead.")] + public virtual IHttpResponse DoHttpPostRequest(string url, IHttpPostData postData) { + return DoHttpRequest(HttpMethod.Post, url, null, postData); + } + + /// + /// Makes a POST request to the specified . + /// + /// The URL of the request. + /// The query string of the request. + /// The POST data of the request. + /// An instance of representing the response. + [Obsolete("Use the Post method instead.")] + public virtual IHttpResponse DoHttpPostRequest(string url, IHttpQueryString queryString, IHttpPostData postData) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return DoHttpRequest(HttpMethod.Post, url, queryString, postData); + } + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The URL of the request. + /// The query string of the request. + /// The content type of the request - eg. application/json. + /// The body of the request. + /// An instance of representing the response. + [Obsolete("Use the Post method instead.")] + public virtual IHttpResponse DoHttpPostRequest(string url, IHttpQueryString queryString, string contentType, string body) { + return DoHttpRequest(HttpMethod.Post, url, queryString, contentType, body); + } + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The body of the request. + /// An instance of representing the raw response. + [Obsolete("Use the Post method instead.")] + public virtual IHttpResponse DoHttpPostRequest(string url, JToken body) { + if (body == null) throw new ArgumentNullException(nameof(body)); + return DoHttpRequest(HttpMethod.Post, url, default(IHttpQueryString), body); + } + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The body of the request. + /// The formatting to be used when serializing . + /// An instance of representing the raw response. + [Obsolete("Use the Post method instead.")] + public virtual IHttpResponse DoHttpPostRequest(string url, JToken body, Formatting formatting) { + if (body == null) throw new ArgumentNullException(nameof(body)); + return DoHttpRequest(HttpMethod.Post, url, default(IHttpQueryString), body); + } + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + [Obsolete("Use the Post method instead.")] + public virtual IHttpResponse DoHttpPostRequest(string url, IHttpQueryString queryString, JToken body) { + if (body == null) throw new ArgumentNullException(nameof(body)); + return DoHttpRequest(HttpMethod.Post, url, queryString, body); + } + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// The formatting to be used when serializing . + /// An instance of representing the raw response. + [Obsolete("Use the Post method instead.")] + public virtual IHttpResponse DoHttpPostRequest(string url, IHttpQueryString queryString, JToken body, Formatting formatting) { + if (body == null) throw new ArgumentNullException(nameof(body)); + return DoHttpRequest(HttpMethod.Post, url, queryString, body); + } + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The body of the request. + /// An instance of representing the raw response. + [Obsolete("Use the Post method instead.")] + public virtual IHttpResponse DoHttpPostRequest(string url, XNode body) { + if (body == null) throw new ArgumentNullException(nameof(body)); + return DoHttpRequest(HttpMethod.Post, url, default(IHttpQueryString), body); + } + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The body of the request. + /// The options to be used when serializing . + /// An instance of representing the raw response. + [Obsolete("Use the Post method instead.")] + public virtual IHttpResponse DoHttpPostRequest(string url, XNode body, SaveOptions options) { + if (body == null) throw new ArgumentNullException(nameof(body)); + return DoHttpRequest(HttpMethod.Post, url, default(IHttpQueryString), body); + } + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + [Obsolete("Use the Post method instead.")] + public virtual IHttpResponse DoHttpPostRequest(string url, IHttpQueryString queryString, XNode body) { + if (body == null) throw new ArgumentNullException(nameof(body)); + return DoHttpRequest(HttpMethod.Post, url, queryString, body); + } + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// The options to be used when serializing . + /// An instance of representing the raw response. + [Obsolete("Use the Post method instead.")] + public virtual IHttpResponse DoHttpPostRequest(string url, IHttpQueryString queryString, XNode body, SaveOptions options) { + if (body == null) throw new ArgumentNullException(nameof(body)); + return DoHttpRequest(HttpMethod.Post, url, queryString, body, options); + } + + #endregion + + #region DoHttpPutRequest + + /// + /// Makes a PUT request to the specified . + /// + /// The URL of the request. + /// An instance of representing the response. + [Obsolete("Use the Put method instead.")] + public virtual IHttpResponse DoHttpPutRequest(string url) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return DoHttpRequest(HttpMethod.Put, url, default(IHttpQueryString), default(IHttpPostData)); + } + + /// + /// Makes a PUT request to the specified . + /// + /// The URL of the request. + /// The options for the call to the specified . + /// An instance of representing the response. + [Obsolete("Use the Put method instead.")] + public virtual IHttpResponse DoHttpPutRequest(string url, IHttpGetOptions options) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + if (options == null) throw new ArgumentNullException(nameof(options)); + return DoHttpRequest(HttpMethod.Put, url, options.GetQueryString(), default(IHttpPostData)); + } + + /// + /// Makes a PUT request to the specified . + /// + /// The URL of the request. + /// The options for the call to the specified . + /// An instance of representing the response. + [Obsolete("Use the Put method instead.")] + public virtual IHttpResponse DoHttpPutRequest(string url, IHttpPostOptions options) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + if (options == null) throw new ArgumentNullException(nameof(options)); + return DoHttpRequest(HttpMethod.Put, url, options.GetQueryString(), options.GetPostData()); + } + + /// + /// Makes a PUT request to the specified . + /// + /// The base URL of the request (no query string). + /// The query string. + /// An instance of representing the raw response. + [Obsolete("Use the Put method instead.")] + public virtual IHttpResponse DoHttpPutRequest(string url, IHttpQueryString queryString) { + return DoHttpRequest(HttpMethod.Put, url, queryString, default(IHttpPostData)); + } + + /// + /// Makes a PUT request to the specified . + /// + /// The base URL of the request (no query string). + /// The POST data. + /// An instance of representing the raw response. + [Obsolete("Use the Put method instead.")] + public virtual IHttpResponse DoHttpPutRequest(string url, IHttpPostData postData) { + return DoHttpRequest(HttpMethod.Put, url, null, postData); + } + + /// + /// Makes a PUT request to the specified . + /// + /// The URL of the request. + /// The query string of the request. + /// The POST data of the request. + /// An instance of representing the response. + [Obsolete("Use the Put method instead.")] + public virtual IHttpResponse DoHttpPutRequest(string url, IHttpQueryString queryString, IHttpPostData postData) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return DoHttpRequest(HttpMethod.Put, url, queryString, postData); + } + + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The URL of the request. + /// The query string of the request. + /// The content type of the request - eg. application/json. + /// The body of the request. + /// An instance of representing the response. + [Obsolete("Use the Put method instead.")] + public virtual IHttpResponse DoHttpPutRequest(string url, IHttpQueryString queryString, string contentType, string body) { + return DoHttpRequest(HttpMethod.Put, url, queryString, contentType, body); + } + + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The body of the request. + /// An instance of representing the raw response. + [Obsolete("Use the Put method instead.")] + public virtual IHttpResponse DoHttpPutRequest(string url, JToken body) { + if (body == null) throw new ArgumentNullException(nameof(body)); + return DoHttpRequest(HttpMethod.Put, url, default(IHttpQueryString), body); + } + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The body of the request. + /// The formatting to be used when serializing . + /// An instance of representing the raw response. + [Obsolete("Use the Put method instead.")] + public virtual IHttpResponse DoHttpPutRequest(string url, JToken body, Formatting formatting) { + if (body == null) throw new ArgumentNullException(nameof(body)); + return DoHttpRequest(HttpMethod.Put, url, default(IHttpQueryString), body); + } + + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + [Obsolete("Use the Put method instead.")] + public virtual IHttpResponse DoHttpPutRequest(string url, IHttpQueryString queryString, JToken body) { + if (body == null) throw new ArgumentNullException(nameof(body)); + return DoHttpRequest(HttpMethod.Put, url, queryString, body); + } + + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// The formatting to be used when serializing . + /// An instance of representing the raw response. + [Obsolete("Use the Put method instead.")] + public virtual IHttpResponse DoHttpPutRequest(string url, IHttpQueryString queryString, JToken body, Formatting formatting) { + if (body == null) throw new ArgumentNullException(nameof(body)); + return DoHttpRequest(HttpMethod.Put, url, queryString, body); } + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The body of the request. + /// An instance of representing the raw response. + [Obsolete("Use the Put method instead.")] + public virtual IHttpResponse DoHttpPutRequest(string url, XNode body) { + if (body == null) throw new ArgumentNullException(nameof(body)); + return DoHttpRequest(HttpMethod.Put, url, default(IHttpQueryString), body); + } + + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The body of the request. + /// The options to be used when serializing . + /// An instance of representing the raw response. + [Obsolete("Use the Put method instead.")] + public virtual IHttpResponse DoHttpPutRequest(string url, XNode body, SaveOptions options) { + if (body == null) throw new ArgumentNullException(nameof(body)); + return DoHttpRequest(HttpMethod.Put, url, default(IHttpQueryString), body); + } + + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + [Obsolete("Use the Put method instead.")] + public virtual IHttpResponse DoHttpPutRequest(string url, IHttpQueryString queryString, XNode body) { + if (body == null) throw new ArgumentNullException(nameof(body)); + return DoHttpRequest(HttpMethod.Put, url, queryString, body); + } + + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// The options to be used when serializing . + /// An instance of representing the raw response. + [Obsolete("Use the Put method instead.")] + public virtual IHttpResponse DoHttpPutRequest(string url, IHttpQueryString queryString, XNode body, SaveOptions options) { + if (body == null) throw new ArgumentNullException(nameof(body)); + return DoHttpRequest(HttpMethod.Put, url, queryString, body, options); + } + + #endregion + + #region DoHttpPatchRequest + + /// + /// Makes a PATCH request to the specified . + /// + /// The URL of the request. + /// An instance of representing the response. + [Obsolete("Use the Patch method instead.")] + public virtual IHttpResponse DoHttpPatchRequest(string url) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return DoHttpRequest(HttpMethod.Patch, url, default(IHttpQueryString), default(IHttpPostData)); + } + + /// + /// Makes a PATCH request to the specified . + /// + /// The URL of the request. + /// The options for the call to the specified . + /// An instance of representing the response. + [Obsolete("Use the Patch method instead.")] + public virtual IHttpResponse DoHttpPatchRequest(string url, IHttpGetOptions options) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + if (options == null) throw new ArgumentNullException(nameof(options)); + return DoHttpRequest(HttpMethod.Patch, url, options.GetQueryString(), default(IHttpPostData)); + } + + /// + /// Makes a PATCH request to the specified . + /// + /// The URL of the request. + /// The options for the call to the specified . + /// An instance of representing the response. + [Obsolete("Use the Patch method instead.")] + public virtual IHttpResponse DoHttpPatchRequest(string url, IHttpPostOptions options) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + if (options == null) throw new ArgumentNullException(nameof(options)); + return DoHttpRequest(HttpMethod.Patch, url, options.GetQueryString(), options.GetPostData()); + } + + /// + /// Makes a PATCH request to the specified . + /// + /// The base URL of the request (no query string). + /// The query string. + /// An instance of representing the raw response. + [Obsolete("Use the Patch method instead.")] + public virtual IHttpResponse DoHttpPatchRequest(string url, IHttpQueryString queryString) { + return DoHttpRequest(HttpMethod.Patch, url, queryString, default(IHttpPostData)); + } + + /// + /// Makes a PATCH request to the specified . + /// + /// The base URL of the request (no query string). + /// The POST data. + /// An instance of representing the raw response. + [Obsolete("Use the Patch method instead.")] + public virtual IHttpResponse DoHttpPatchRequest(string url, IHttpPostData postData) { + return DoHttpRequest(HttpMethod.Patch, url, null, postData); + } + + /// + /// Makes a PATCH request to the specified . + /// + /// The URL of the request. + /// The query string of the request. + /// The POST data of the request. + /// An instance of representing the response. + [Obsolete("Use the Patch method instead.")] + public virtual IHttpResponse DoHttpPatchRequest(string url, IHttpQueryString queryString, IHttpPostData postData) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return DoHttpRequest(HttpMethod.Patch, url, queryString, postData); + } + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The URL of the request. + /// The query string of the request. + /// The content type of the request - eg. application/json. + /// The body of the request. + /// An instance of representing the response. + [Obsolete("Use the Patch method instead.")] + public virtual IHttpResponse DoHttpPatchRequest(string url, IHttpQueryString queryString, string contentType, string body) { + return DoHttpRequest(HttpMethod.Patch, url, queryString, contentType, body); + } + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The body of the request. + /// An instance of representing the raw response. + [Obsolete("Use the Patch method instead.")] + public virtual IHttpResponse DoHttpPatchRequest(string url, JToken body) { + if (body == null) throw new ArgumentNullException(nameof(body)); + return DoHttpRequest(HttpMethod.Patch, url, default(IHttpQueryString), body); + } + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The body of the request. + /// The formatting to be used when serializing . + /// An instance of representing the raw response. + [Obsolete("Use the Patch method instead.")] + public virtual IHttpResponse DoHttpPatchRequest(string url, JToken body, Formatting formatting) { + if (body == null) throw new ArgumentNullException(nameof(body)); + return DoHttpRequest(HttpMethod.Patch, url, default(IHttpQueryString), body); + } + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + [Obsolete("Use the Patch method instead.")] + public virtual IHttpResponse DoHttpPatchRequest(string url, IHttpQueryString queryString, JToken body) { + if (body == null) throw new ArgumentNullException(nameof(body)); + return DoHttpRequest(HttpMethod.Patch, url, queryString, body); + } + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// The formatting to be used when serializing . + /// An instance of representing the raw response. + [Obsolete("Use the Patch method instead.")] + public virtual IHttpResponse DoHttpPatchRequest(string url, IHttpQueryString queryString, JToken body, Formatting formatting) { + if (body == null) throw new ArgumentNullException(nameof(body)); + return DoHttpRequest(HttpMethod.Patch, url, queryString, body); + } + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The body of the request. + /// An instance of representing the raw response. + [Obsolete("Use the Patch method instead.")] + public virtual IHttpResponse DoHttpPatchRequest(string url, XNode body) { + if (body == null) throw new ArgumentNullException(nameof(body)); + return DoHttpRequest(HttpMethod.Patch, url, default(IHttpQueryString), body); + } + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The body of the request. + /// The options to be used when serializing . + /// An instance of representing the raw response. + [Obsolete("Use the Patch method instead.")] + public virtual IHttpResponse DoHttpPatchRequest(string url, XNode body, SaveOptions options) { + if (body == null) throw new ArgumentNullException(nameof(body)); + return DoHttpRequest(HttpMethod.Patch, url, default(IHttpQueryString), body); + } + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + [Obsolete("Use the Patch method instead.")] + public virtual IHttpResponse DoHttpPatchRequest(string url, IHttpQueryString? queryString, XNode body) { + if (body == null) throw new ArgumentNullException(nameof(body)); + return DoHttpRequest(HttpMethod.Patch, url, queryString, body); + } + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// The options to be used when serializing . + /// An instance of representing the raw response. + [Obsolete("Use the Patch method instead.")] + public virtual IHttpResponse DoHttpPatchRequest(string url, IHttpQueryString? queryString, XNode body, SaveOptions options) { + if (body == null) throw new ArgumentNullException(nameof(body)); + return DoHttpRequest(HttpMethod.Patch, url, queryString, body, options); + } + + #endregion + + #region DoHttpDeleteRequest + + /// + /// Makes a HTTP DELETE request to the specified . + /// + /// The URL of the request. + /// An instance of representing the response. + [Obsolete("Use the Delete method instead.")] + public virtual IHttpResponse DoHttpDeleteRequest(string url) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return DoHttpRequest(HttpMethod.Delete, url, default(IHttpQueryString)); + } + + /// + /// Makes a DELETE request to the specified . + /// + /// The URL of the request. + /// The options for the call to the specified . + /// An instance of representing the response. + [Obsolete("Use the Delete method instead.")] + public virtual IHttpResponse DoHttpDeleteRequest(string url, IHttpGetOptions options) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + if (options == null) throw new ArgumentNullException(nameof(options)); + return DoHttpRequest(HttpMethod.Delete, url, options.GetQueryString()); + } + + /// + /// Makes a DELETE request to the specified . + /// + /// The URL of the request. + /// The query string of the request. + /// An instance of representing the response. + [Obsolete("Use the Delete method instead.")] + public virtual IHttpResponse DoHttpDeleteRequest(string url, IHttpQueryString? queryString) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return DoHttpRequest(HttpMethod.Delete, url, queryString); + } + + #endregion + + #region DoHttpRequest + + /// + /// Makes a HTTP request to the underlying API based on the specified parameters. + /// + /// The HTTP method of the request. + /// The base URL of the request (no query string). + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + public virtual IHttpResponse DoHttpRequest(HttpMethod method, string url) { + return DoHttpRequest(method, url, default(IHttpQueryString), default(IHttpPostData)); + } + + /// + /// Makes a HTTP request to the underlying API based on the specified parameters. + /// + /// The HTTP method of the request. + /// The base URL of the request (no query string). + /// The options for the call to the API. + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + public virtual IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpGetOptions options) { + if (options == null) throw new ArgumentNullException(nameof(options)); + return DoHttpRequest(method, url, options.GetQueryString()); + } + + /// + /// Makes a HTTP request to the underlying API based on the specified parameters. + /// + /// The HTTP method of the request. + /// The base URL of the request (no query string). + /// The query string. + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + public virtual IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpQueryString? queryString) { + return DoHttpRequest(method, url, queryString, default(IHttpPostData)); + } + + /// + /// Makes a HTTP request to the underlying API based on the specified parameters. + /// + /// The HTTP method of the request. + /// The base URL of the request (no query string). + /// The POST data. + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + public virtual IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpPostData? postData) { + return DoHttpRequest(method, url, null, postData); + } + + /// + /// Makes a HTTP request to the underlying API based on the specified parameters. + /// + /// The HTTP method of the request. + /// The base URL of the request (no query string). + /// The query string. + /// The POST data. + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + public virtual IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpQueryString? queryString, IHttpPostData? postData) { + + // Some input validation + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + + // Initialize the request + HttpRequest request = new() { + Method = method, + Url = url, + QueryString = queryString!, + PostData = postData! + }; + + PrepareHttpRequest(request); + + // Make the call to the URL + return request.GetResponse(); + + } + + /// + /// Makes a HTTP request to the underlying API based on the specified parameters. + /// + /// The HTTP method of the request. + /// The base URL of the request (no query string). + /// The query string. + /// The content type of the request - eg. application/json. + /// The body of the request. + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + public virtual IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpQueryString? queryString, string? contentType, string? body) { + + // Some input validation + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + + // Initialize the request + HttpRequest request = new() { + Method = method, + Url = url, + QueryString = queryString!, + ContentType = contentType, + Body = body + }; + + PrepareHttpRequest(request); + + // Make the call to the URL + return request.GetResponse(); + + } + + /// + /// Makes a HTTP request based on the specified parameters. + /// + /// The HTTP method of the request. + /// The base URL of the request (no query string). + /// The body of the request. + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + public virtual IHttpResponse DoHttpRequest(HttpMethod method, string url, JToken body) { + if (body == null) throw new ArgumentNullException(nameof(body)); + return DoHttpRequest(method, url, default(IHttpQueryString), HttpConstants.ApplicationJson, body.ToString(Formatting.None)); + } + + /// + /// Makes a HTTP request based on the specified parameters. + /// + /// The HTTP method of the request. + /// The base URL of the request (no query string). + /// The body of the request. + /// The formatting to be used when serializing . + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + public virtual IHttpResponse DoHttpRequest(HttpMethod method, string url, JToken body, Formatting formatting) { + if (body == null) throw new ArgumentNullException(nameof(body)); + return DoHttpRequest(method, url, default(IHttpQueryString), HttpConstants.ApplicationJson, body.ToString(formatting)); + } + + /// + /// Makes a HTTP request based on the specified parameters. + /// + /// The HTTP method of the request. + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + public virtual IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpQueryString? queryString, JToken body) { + if (body == null) throw new ArgumentNullException(nameof(body)); + return DoHttpRequest(method, url, queryString, HttpConstants.ApplicationJson, body.ToString(Formatting.None)); + } + + /// + /// Makes a HTTP request based on the specified parameters. + /// + /// The HTTP method of the request. + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// The formatting to be used when serializing . + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + public virtual IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpQueryString? queryString, JToken body, Formatting formatting) { + if (body == null) throw new ArgumentNullException(nameof(body)); + return DoHttpRequest(method, url, queryString, HttpConstants.ApplicationJson, body.ToString(formatting)); + } + + /// + /// Makes a HTTP request based on the specified parameters. + /// + /// The HTTP method of the request. + /// The base URL of the request (no query string). + /// The body of the request. + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + public virtual IHttpResponse DoHttpRequest(HttpMethod method, string url, XNode body) { + if (body == null) throw new ArgumentNullException(nameof(body)); + return DoHttpRequest(method, url, default(IHttpQueryString), HttpConstants.TextXml, body.ToString(SaveOptions.None)); + } + + /// + /// Makes a HTTP request based on the specified parameters. + /// + /// The HTTP method of the request. + /// The base URL of the request (no query string). + /// The body of the request. + /// The options to be used when serializing . + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + public virtual IHttpResponse DoHttpRequest(HttpMethod method, string url, XNode body, SaveOptions options) { + if (body == null) throw new ArgumentNullException(nameof(body)); + return DoHttpRequest(method, url, default(IHttpQueryString), HttpConstants.TextXml, body.ToString(options)); + } + + /// + /// Makes a HTTP request based on the specified parameters. + /// + /// The HTTP method of the request. + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + public virtual IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpQueryString? queryString, XNode body) { + if (body == null) throw new ArgumentNullException(nameof(body)); + return DoHttpRequest(method, url, queryString, HttpConstants.TextXml, body.ToString(SaveOptions.None)); + } + + /// + /// Makes a HTTP request based on the specified parameters. + /// + /// The HTTP method of the request. + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// The options to be used when serializing . + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + public virtual IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpQueryString? queryString, XNode body, SaveOptions options) { + if (body == null) throw new ArgumentNullException(nameof(body)); + return DoHttpRequest(method, url, queryString, HttpConstants.TextXml, body.ToString(options)); + } + + #endregion + + #region Other + + /// + /// Returns the response of the request identified by the specified . + /// + /// The options for the request to the API. + /// An instance of representing the raw response. + public virtual IHttpResponse GetResponse(IHttpRequestOptions options) { + if (options == null) throw new ArgumentNullException(nameof(options)); + IHttpRequest request = options.GetRequest(); + PrepareHttpRequest(request); + return request.GetResponse(); + } + + /// + /// Sends a new request as described by and returns the response. + /// + /// An instance of describing the request. + /// An instance of representing the raw response. + public virtual IHttpResponse GetResponse(IHttpRequest request) { + if (request == null) throw new ArgumentNullException(nameof(request)); + PrepareHttpRequest(request); + return request.GetResponse(); + } + + /// + /// Executes a new the request described by the specified and returns the + /// response as an instance of . + /// + /// An instance of representing the response. + public async Task GetResponseAsync(IHttpRequestOptions options) { + if (options == null) throw new ArgumentNullException(nameof(options)); + IHttpRequest request = options.GetRequest(); + PrepareHttpRequest(request); + return await request.GetResponseAsync(); + } + + /// + /// Executes the specified and returns the response as an instance of + /// . + /// + /// An instance of describing the request. + /// An instance of representing the raw response. + public virtual async Task GetResponseAsync(IHttpRequest request) { + if (request == null) throw new ArgumentNullException(nameof(request)); + PrepareHttpRequest(request); + return await request.GetResponseAsync(); + } + + /// + /// Virtual method that can be used for configuring a request. + /// + /// The request. + protected virtual void PrepareHttpRequest(IHttpRequest request) { } + + #endregion + } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/Client/HttpClientAsyncExtensions.cs b/src/Skybrud.Essentials.Http/Client/HttpClientAsyncExtensions.cs index edd127f..75cfa66 100644 --- a/src/Skybrud.Essentials.Http/Client/HttpClientAsyncExtensions.cs +++ b/src/Skybrud.Essentials.Http/Client/HttpClientAsyncExtensions.cs @@ -5,860 +5,858 @@ using System.Threading.Tasks; using System.Xml.Linq; -namespace Skybrud.Essentials.Http.Client { +namespace Skybrud.Essentials.Http.Client; - /// - /// Static class with various extension methods for . - /// - public static class HttpClientAsyncExtensions { +/// +/// Static class with various extension methods for . +/// +public static class HttpClientAsyncExtensions { - #region GetAsync(...) + #region GetAsync(...) - /// - /// Makes a HTTP GET request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// An instance of representing the response. - public static async Task GetAsync(this IHttpClientAsync client, string url) { - return await client.GetResponseAsync(HttpRequest.Get(url)); - } + /// + /// Makes a HTTP GET request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// An instance of representing the response. + public static async Task GetAsync(this IHttpClientAsync client, string url) { + return await client.GetResponseAsync(HttpRequest.Get(url)); + } - /// - /// Makes a GET request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// The query string of the request. - /// An instance of representing the response. - public static async Task GetAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString) { - return await client.GetResponseAsync(HttpRequest.Get(url, queryString)); - } + /// + /// Makes a GET request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// The query string of the request. + /// An instance of representing the response. + public static async Task GetAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString) { + return await client.GetResponseAsync(HttpRequest.Get(url, queryString)); + } #if NAME_VALUE_COLLECTION - /// - /// Makes a GET request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// The query string of the request. - /// An instance of representing the response. - public static async Task GetAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return await client.GetResponseAsync(HttpRequest.Get(url, query)); - } + /// + /// Makes a GET request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// The query string of the request. + /// An instance of representing the response. + public static async Task GetAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return await client.GetResponseAsync(HttpRequest.Get(url, query)); + } #endif - #endregion - - #region PostAsync(...) - - /// - /// Makes a POST request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// An instance of representing the response. - public static async Task PostAsync(this IHttpClientAsync client, string url) { - return await client.GetResponseAsync(HttpRequest.Post(url)); - } - - /// - /// Makes a POST request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// An instance of representing the raw response. - public static async Task PostAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString) { - return await client.GetResponseAsync(HttpRequest.Post(url, queryString)); - } - - /// - /// Makes a POST request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// The POST data. - /// An instance of representing the raw response. - public static async Task PostAsync(this IHttpClientAsync client, string url, IHttpPostData? postData) { - return await client.GetResponseAsync(HttpRequest.Post(url, null, postData)); - } - - /// - /// Makes a POST request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// The query string of the request. - /// The POST data of the request. - /// An instance of representing the response. - public static async Task PostAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString, IHttpPostData? postData) { - return await client.GetResponseAsync(HttpRequest.Post(url, queryString, postData)); - } - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string of the request. - /// The content type of the request - eg. application/json. - /// The body of the request. - /// An instance of representing the response. - public static async Task PostAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString, string? contentType, string? body) { - return await client.GetResponseAsync(HttpRequest.Post(url, queryString, contentType, body)); - } - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The body of the request. - /// An instance of representing the raw response. - public static async Task PostAsync(this IHttpClientAsync client, string url, JToken body) { - return await client.GetResponseAsync(HttpRequest.Post(url, body)); - } - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The body of the request. - /// The formatting to be used when serializing . - /// An instance of representing the raw response. - public static async Task PostAsync(this IHttpClientAsync client, string url, JToken body, Formatting formatting) { - return await client.GetResponseAsync(HttpRequest.Post(url, body, formatting)); - } - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - public static async Task PostAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString, JToken body) { - return await client.GetResponseAsync(HttpRequest.Post(url, queryString, body)); - } - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// The formatting to be used when serializing . - /// An instance of representing the raw response. - public static async Task PostAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString, JToken body, Formatting formatting) { - return await client.GetResponseAsync(HttpRequest.Post(url, queryString, body, formatting)); - } - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The body of the request. - /// An instance of representing the raw response. - public static async Task PostAsync(this IHttpClientAsync client, string url, XNode body) { - return await client.GetResponseAsync(HttpRequest.Post(url, body)); - } - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The body of the request. - /// The options to be used when serializing . - /// An instance of representing the raw response. - public static async Task PostAsync(this IHttpClientAsync client, string url, XNode body, SaveOptions options) { - return await client.GetResponseAsync(HttpRequest.Post(url, body, options)); - } - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - public static async Task PostAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString, XNode body) { - return await client.GetResponseAsync(HttpRequest.Post(url, queryString, body)); - } - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// The options to be used when serializing . - /// An instance of representing the raw response. - public static async Task PostAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString, XNode body, SaveOptions options) { - return await client.GetResponseAsync(HttpRequest.Post(url, queryString, body, options)); - } + #endregion -#if NAME_VALUE_COLLECTION + #region PostAsync(...) - /// - /// Makes a POST request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// An instance of representing the raw response. - public static async Task PostAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return await client.GetResponseAsync(HttpRequest.Post(url, query)); - } - - /// - /// Makes a POST request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// The query string of the request. - /// The POST data of the request. - /// An instance of representing the response. - public static async Task PostAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString, NameValueCollection? postData) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - IHttpPostData? post = postData == null ? null : new HttpPostData(postData); - return await client.GetResponseAsync(HttpRequest.Post(url, query, post)); - } - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string of the request. - /// The content type of the request - eg. application/json. - /// The body of the request. - /// An instance of representing the response. - public static async Task PostAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString, string contentType, string body) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return await client.GetResponseAsync(HttpRequest.Post(url, query, contentType, body)); - } - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - public static async Task PostAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString, JToken body) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return await client.GetResponseAsync(HttpRequest.Post(url, query, body)); - } - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// The formatting to be used when serializing . - /// An instance of representing the raw response. - public static async Task PostAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString, JToken body, Formatting formatting) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return await client.GetResponseAsync(HttpRequest.Post(url, query, body, formatting)); - } - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - public static async Task PostAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString, XNode body) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return await client.GetResponseAsync(HttpRequest.Post(url, query, body)); - } - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// The options to be used when serializing . - /// An instance of representing the raw response. - public static async Task PostAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString, XNode body, SaveOptions options) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return await client.GetResponseAsync(HttpRequest.Post(url, query, body, options)); - } + /// + /// Makes a POST request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// An instance of representing the response. + public static async Task PostAsync(this IHttpClientAsync client, string url) { + return await client.GetResponseAsync(HttpRequest.Post(url)); + } -#endif + /// + /// Makes a POST request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// An instance of representing the raw response. + public static async Task PostAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString) { + return await client.GetResponseAsync(HttpRequest.Post(url, queryString)); + } - #endregion - - #region PatchAsync(...) - - /// - /// Makes a PATCH request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// An instance of representing the response. - public static async Task PatchAsync(this IHttpClientAsync client, string url) { - return await client.GetResponseAsync(HttpRequest.Patch(url)); - } - - /// - /// Makes a PATCH request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// An instance of representing the raw response. - public static async Task PatchAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString) { - return await client.GetResponseAsync(HttpRequest.Patch(url, queryString)); - } - - /// - /// Makes a PATCH request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// The POST data. - /// An instance of representing the raw response. - public static async Task PatchAsync(this IHttpClientAsync client, string url, IHttpPostData? postData) { - return await client.GetResponseAsync(HttpRequest.Patch(url, postData)); - } - - /// - /// Makes a PATCH request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// The query string of the request. - /// The POST data of the request. - /// An instance of representing the response. - public static async Task PatchAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString, IHttpPostData? postData) { - return await client.GetResponseAsync(HttpRequest.Patch(url, queryString, postData)); - } - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string of the request. - /// The content type of the request - eg. application/json. - /// The body of the request. - /// An instance of representing the response. - public static async Task PatchAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString, string contentType, string body) { - return await client.GetResponseAsync(HttpRequest.Patch(url, queryString, contentType, body)); - } - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The body of the request. - /// An instance of representing the raw response. - public static async Task PatchAsync(this IHttpClientAsync client, string url, JToken body) { - return await client.GetResponseAsync(HttpRequest.Patch(url, body)); - } - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The body of the request. - /// The formatting to be used when serializing . - /// An instance of representing the raw response. - public static async Task PatchAsync(this IHttpClientAsync client, string url, JToken body, Formatting formatting) { - return await client.GetResponseAsync(HttpRequest.Patch(url, body, formatting)); - } - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - public static async Task PatchAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString, JToken body) { - return await client.GetResponseAsync(HttpRequest.Patch(url, queryString, body)); - } - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// The formatting to be used when serializing . - /// An instance of representing the raw response. - public static async Task PatchAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString, JToken body, Formatting formatting) { - return await client.GetResponseAsync(HttpRequest.Patch(url, queryString, body, formatting)); - } - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The body of the request. - /// An instance of representing the raw response. - public static async Task PatchAsync(this IHttpClientAsync client, string url, XNode body) { - return await client.GetResponseAsync(HttpRequest.Patch(url, body)); - } - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The body of the request. - /// The options to be used when serializing . - /// An instance of representing the raw response. - public static async Task PatchAsync(this IHttpClientAsync client, string url, XNode body, SaveOptions options) { - return await client.GetResponseAsync(HttpRequest.Patch(url, body, options)); - } - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - public static async Task PatchAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString, XNode body) { - return await client.GetResponseAsync(HttpRequest.Patch(url, queryString, body)); - } - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// The options to be used when serializing . - /// An instance of representing the raw response. - public static async Task PatchAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString, XNode body, SaveOptions options) { - return await client.GetResponseAsync(HttpRequest.Patch(url, queryString, body, options)); - } + /// + /// Makes a POST request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// The POST data. + /// An instance of representing the raw response. + public static async Task PostAsync(this IHttpClientAsync client, string url, IHttpPostData? postData) { + return await client.GetResponseAsync(HttpRequest.Post(url, null, postData)); + } + + /// + /// Makes a POST request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// The query string of the request. + /// The POST data of the request. + /// An instance of representing the response. + public static async Task PostAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString, IHttpPostData? postData) { + return await client.GetResponseAsync(HttpRequest.Post(url, queryString, postData)); + } + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string of the request. + /// The content type of the request - eg. application/json. + /// The body of the request. + /// An instance of representing the response. + public static async Task PostAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString, string? contentType, string? body) { + return await client.GetResponseAsync(HttpRequest.Post(url, queryString, contentType, body)); + } + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The body of the request. + /// An instance of representing the raw response. + public static async Task PostAsync(this IHttpClientAsync client, string url, JToken body) { + return await client.GetResponseAsync(HttpRequest.Post(url, body)); + } + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The body of the request. + /// The formatting to be used when serializing . + /// An instance of representing the raw response. + public static async Task PostAsync(this IHttpClientAsync client, string url, JToken body, Formatting formatting) { + return await client.GetResponseAsync(HttpRequest.Post(url, body, formatting)); + } + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + public static async Task PostAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString, JToken body) { + return await client.GetResponseAsync(HttpRequest.Post(url, queryString, body)); + } + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// The formatting to be used when serializing . + /// An instance of representing the raw response. + public static async Task PostAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString, JToken body, Formatting formatting) { + return await client.GetResponseAsync(HttpRequest.Post(url, queryString, body, formatting)); + } + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The body of the request. + /// An instance of representing the raw response. + public static async Task PostAsync(this IHttpClientAsync client, string url, XNode body) { + return await client.GetResponseAsync(HttpRequest.Post(url, body)); + } + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The body of the request. + /// The options to be used when serializing . + /// An instance of representing the raw response. + public static async Task PostAsync(this IHttpClientAsync client, string url, XNode body, SaveOptions options) { + return await client.GetResponseAsync(HttpRequest.Post(url, body, options)); + } + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + public static async Task PostAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString, XNode body) { + return await client.GetResponseAsync(HttpRequest.Post(url, queryString, body)); + } + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// The options to be used when serializing . + /// An instance of representing the raw response. + public static async Task PostAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString, XNode body, SaveOptions options) { + return await client.GetResponseAsync(HttpRequest.Post(url, queryString, body, options)); + } #if NAME_VALUE_COLLECTION - /// - /// Makes a PATCH request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// An instance of representing the raw response. - public static async Task PatchAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return await client.GetResponseAsync(HttpRequest.Patch(url, query)); - } - - /// - /// Makes a PATCH request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// The query string of the request. - /// The POST data of the request. - /// An instance of representing the response. - public static async Task PatchAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString, NameValueCollection? postData) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - IHttpPostData? post = postData == null ? null : new HttpPostData(postData); - return await client.GetResponseAsync(HttpRequest.Patch(url, query, post)); - } - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string of the request. - /// The content type of the request - eg. application/json. - /// The body of the request. - /// An instance of representing the response. - public static async Task PatchAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString, string contentType, string body) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return await client.GetResponseAsync(HttpRequest.Patch(url, query, contentType, body)); - } - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - public static async Task PatchAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString, JToken body) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return await client.GetResponseAsync(HttpRequest.Patch(url, query, body)); - } - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// The formatting to be used when serializing . - /// An instance of representing the raw response. - public static async Task PatchAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString, JToken body, Formatting formatting) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return await client.GetResponseAsync(HttpRequest.Patch(url, query, body, formatting)); - } - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - public static async Task PatchAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString, XNode body) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return await client.GetResponseAsync(HttpRequest.Patch(url, query, body)); - } - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// The options to be used when serializing . - /// An instance of representing the raw response. - public static async Task PatchAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString, XNode body, SaveOptions options) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return await client.GetResponseAsync(HttpRequest.Patch(url, query, body, options)); - } + /// + /// Makes a POST request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// An instance of representing the raw response. + public static async Task PostAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return await client.GetResponseAsync(HttpRequest.Post(url, query)); + } + + /// + /// Makes a POST request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// The query string of the request. + /// The POST data of the request. + /// An instance of representing the response. + public static async Task PostAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString, NameValueCollection? postData) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + IHttpPostData? post = postData == null ? null : new HttpPostData(postData); + return await client.GetResponseAsync(HttpRequest.Post(url, query, post)); + } + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string of the request. + /// The content type of the request - eg. application/json. + /// The body of the request. + /// An instance of representing the response. + public static async Task PostAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString, string contentType, string body) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return await client.GetResponseAsync(HttpRequest.Post(url, query, contentType, body)); + } + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + public static async Task PostAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString, JToken body) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return await client.GetResponseAsync(HttpRequest.Post(url, query, body)); + } + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// The formatting to be used when serializing . + /// An instance of representing the raw response. + public static async Task PostAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString, JToken body, Formatting formatting) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return await client.GetResponseAsync(HttpRequest.Post(url, query, body, formatting)); + } + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + public static async Task PostAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString, XNode body) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return await client.GetResponseAsync(HttpRequest.Post(url, query, body)); + } + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// The options to be used when serializing . + /// An instance of representing the raw response. + public static async Task PostAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString, XNode body, SaveOptions options) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return await client.GetResponseAsync(HttpRequest.Post(url, query, body, options)); + } #endif - #endregion - - #region PutAsync(...) - - /// - /// Makes a PUT request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// An instance of representing the response. - public static async Task PutAsync(this IHttpClientAsync client, string url) { - return await client.GetResponseAsync(HttpRequest.Put(url)); - } - - /// - /// Makes a PUT request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// An instance of representing the raw response. - public static async Task PutAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString) { - return await client.GetResponseAsync(HttpRequest.Put(url, queryString)); - } - - /// - /// Makes a PUT request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// The POST data. - /// An instance of representing the raw response. - public static async Task PutAsync(this IHttpClientAsync client, string url, IHttpPostData? postData) { - return await client.GetResponseAsync(HttpRequest.Put(url, postData)); - } - - /// - /// Makes a PUT request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// The query string of the request. - /// The POST data of the request. - /// An instance of representing the response. - public static async Task PutAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString, IHttpPostData? postData) { - return await client.GetResponseAsync(HttpRequest.Put(url, queryString, postData)); - } - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string of the request. - /// The content type of the request - eg. application/json. - /// The body of the request. - /// An instance of representing the response. - public static async Task PutAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString, string contentType, string body) { - return await client.GetResponseAsync(HttpRequest.Put(url, queryString, contentType, body)); - } - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The body of the request. - /// An instance of representing the raw response. - public static async Task PutAsync(this IHttpClientAsync client, string url, JToken body) { - return await client.GetResponseAsync(HttpRequest.Put(url, body)); - } - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The body of the request. - /// The formatting to be used when serializing . - /// An instance of representing the raw response. - public static async Task PutAsync(this IHttpClientAsync client, string url, JToken body, Formatting formatting) { - return await client.GetResponseAsync(HttpRequest.Put(url, body, formatting)); - } - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - public static async Task PutAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString, JToken body) { - return await client.GetResponseAsync(HttpRequest.Put(url, queryString, body)); - } - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// The formatting to be used when serializing . - /// An instance of representing the raw response. - public static async Task PutAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString, JToken body, Formatting formatting) { - return await client.GetResponseAsync(HttpRequest.Put(url, queryString, body, formatting)); - } - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The body of the request. - /// An instance of representing the raw response. - public static async Task PutAsync(this IHttpClientAsync client, string url, XNode body) { - return await client.GetResponseAsync(HttpRequest.Put(url, body)); - } - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The body of the request. - /// The options to be used when serializing . - /// An instance of representing the raw response. - public static async Task PutAsync(this IHttpClientAsync client, string url, XNode body, SaveOptions options) { - return await client.GetResponseAsync(HttpRequest.Put(url, body, options)); - } - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - public static async Task PutAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString, XNode body) { - return await client.GetResponseAsync(HttpRequest.Put(url, queryString, body)); - } - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// The options to be used when serializing . - /// An instance of representing the raw response. - public static async Task PutAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString, XNode body, SaveOptions options) { - return await client.GetResponseAsync(HttpRequest.Put(url, queryString, body, options)); - } + #endregion + + #region PatchAsync(...) + + /// + /// Makes a PATCH request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// An instance of representing the response. + public static async Task PatchAsync(this IHttpClientAsync client, string url) { + return await client.GetResponseAsync(HttpRequest.Patch(url)); + } + + /// + /// Makes a PATCH request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// An instance of representing the raw response. + public static async Task PatchAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString) { + return await client.GetResponseAsync(HttpRequest.Patch(url, queryString)); + } + + /// + /// Makes a PATCH request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// The POST data. + /// An instance of representing the raw response. + public static async Task PatchAsync(this IHttpClientAsync client, string url, IHttpPostData? postData) { + return await client.GetResponseAsync(HttpRequest.Patch(url, postData)); + } + + /// + /// Makes a PATCH request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// The query string of the request. + /// The POST data of the request. + /// An instance of representing the response. + public static async Task PatchAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString, IHttpPostData? postData) { + return await client.GetResponseAsync(HttpRequest.Patch(url, queryString, postData)); + } + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string of the request. + /// The content type of the request - eg. application/json. + /// The body of the request. + /// An instance of representing the response. + public static async Task PatchAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString, string contentType, string body) { + return await client.GetResponseAsync(HttpRequest.Patch(url, queryString, contentType, body)); + } + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The body of the request. + /// An instance of representing the raw response. + public static async Task PatchAsync(this IHttpClientAsync client, string url, JToken body) { + return await client.GetResponseAsync(HttpRequest.Patch(url, body)); + } + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The body of the request. + /// The formatting to be used when serializing . + /// An instance of representing the raw response. + public static async Task PatchAsync(this IHttpClientAsync client, string url, JToken body, Formatting formatting) { + return await client.GetResponseAsync(HttpRequest.Patch(url, body, formatting)); + } + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + public static async Task PatchAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString, JToken body) { + return await client.GetResponseAsync(HttpRequest.Patch(url, queryString, body)); + } + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// The formatting to be used when serializing . + /// An instance of representing the raw response. + public static async Task PatchAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString, JToken body, Formatting formatting) { + return await client.GetResponseAsync(HttpRequest.Patch(url, queryString, body, formatting)); + } + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The body of the request. + /// An instance of representing the raw response. + public static async Task PatchAsync(this IHttpClientAsync client, string url, XNode body) { + return await client.GetResponseAsync(HttpRequest.Patch(url, body)); + } + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The body of the request. + /// The options to be used when serializing . + /// An instance of representing the raw response. + public static async Task PatchAsync(this IHttpClientAsync client, string url, XNode body, SaveOptions options) { + return await client.GetResponseAsync(HttpRequest.Patch(url, body, options)); + } + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + public static async Task PatchAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString, XNode body) { + return await client.GetResponseAsync(HttpRequest.Patch(url, queryString, body)); + } + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// The options to be used when serializing . + /// An instance of representing the raw response. + public static async Task PatchAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString, XNode body, SaveOptions options) { + return await client.GetResponseAsync(HttpRequest.Patch(url, queryString, body, options)); + } #if NAME_VALUE_COLLECTION - /// - /// Makes a PUT request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// An instance of representing the raw response. - public static async Task PutAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return await client.GetResponseAsync(HttpRequest.Put(url, query)); - } - - /// - /// Makes a PUT request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// The query string of the request. - /// The POST data of the request. - /// An instance of representing the response. - public static async Task PutAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString, NameValueCollection? postData) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - IHttpPostData? post = postData == null ? null : new HttpPostData(postData); - return await client.GetResponseAsync(HttpRequest.Put(url, query, post)); - } - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string of the request. - /// The content type of the request - eg. application/json. - /// The body of the request. - /// An instance of representing the response. - public static async Task PutAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString, string contentType, string body) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return await client.GetResponseAsync(HttpRequest.Put(url, query, contentType, body)); - } - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - public static async Task PutAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString, JToken body) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return await client.GetResponseAsync(HttpRequest.Put(url, query, body)); - } - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// The formatting to be used when serializing . - /// An instance of representing the raw response. - public static async Task PutAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString, JToken body, Formatting formatting) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return await client.GetResponseAsync(HttpRequest.Put(url, query, body, formatting)); - } - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - public static async Task PutAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString, XNode body) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return await client.GetResponseAsync(HttpRequest.Put(url, query, body)); - } - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// The options to be used when serializing . - /// An instance of representing the raw response. - public static async Task PutAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString, XNode body, SaveOptions options) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return await client.GetResponseAsync(HttpRequest.Put(url, query, body, options)); - } + /// + /// Makes a PATCH request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// An instance of representing the raw response. + public static async Task PatchAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return await client.GetResponseAsync(HttpRequest.Patch(url, query)); + } + + /// + /// Makes a PATCH request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// The query string of the request. + /// The POST data of the request. + /// An instance of representing the response. + public static async Task PatchAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString, NameValueCollection? postData) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + IHttpPostData? post = postData == null ? null : new HttpPostData(postData); + return await client.GetResponseAsync(HttpRequest.Patch(url, query, post)); + } + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string of the request. + /// The content type of the request - eg. application/json. + /// The body of the request. + /// An instance of representing the response. + public static async Task PatchAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString, string contentType, string body) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return await client.GetResponseAsync(HttpRequest.Patch(url, query, contentType, body)); + } + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + public static async Task PatchAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString, JToken body) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return await client.GetResponseAsync(HttpRequest.Patch(url, query, body)); + } + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// The formatting to be used when serializing . + /// An instance of representing the raw response. + public static async Task PatchAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString, JToken body, Formatting formatting) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return await client.GetResponseAsync(HttpRequest.Patch(url, query, body, formatting)); + } + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + public static async Task PatchAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString, XNode body) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return await client.GetResponseAsync(HttpRequest.Patch(url, query, body)); + } + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// The options to be used when serializing . + /// An instance of representing the raw response. + public static async Task PatchAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString, XNode body, SaveOptions options) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return await client.GetResponseAsync(HttpRequest.Patch(url, query, body, options)); + } #endif - #endregion - - #region DeleteAsync(...) - - /// - /// Makes a HTTP DELETE request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// An instance of representing the response. - public static async Task DeleteAsync(this IHttpClientAsync client, string url) { - return await client.GetResponseAsync(HttpRequest.Delete(url)); - } - - /// - /// Makes a DELETE request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// The query string of the request. - /// An instance of representing the response. - public static async Task DeleteAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString) { - return await client.GetResponseAsync(HttpRequest.Delete(url, queryString)); - } + #endregion + + #region PutAsync(...) + + /// + /// Makes a PUT request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// An instance of representing the response. + public static async Task PutAsync(this IHttpClientAsync client, string url) { + return await client.GetResponseAsync(HttpRequest.Put(url)); + } + + /// + /// Makes a PUT request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// An instance of representing the raw response. + public static async Task PutAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString) { + return await client.GetResponseAsync(HttpRequest.Put(url, queryString)); + } + + /// + /// Makes a PUT request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// The POST data. + /// An instance of representing the raw response. + public static async Task PutAsync(this IHttpClientAsync client, string url, IHttpPostData? postData) { + return await client.GetResponseAsync(HttpRequest.Put(url, postData)); + } + + /// + /// Makes a PUT request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// The query string of the request. + /// The POST data of the request. + /// An instance of representing the response. + public static async Task PutAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString, IHttpPostData? postData) { + return await client.GetResponseAsync(HttpRequest.Put(url, queryString, postData)); + } + + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string of the request. + /// The content type of the request - eg. application/json. + /// The body of the request. + /// An instance of representing the response. + public static async Task PutAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString, string contentType, string body) { + return await client.GetResponseAsync(HttpRequest.Put(url, queryString, contentType, body)); + } + + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The body of the request. + /// An instance of representing the raw response. + public static async Task PutAsync(this IHttpClientAsync client, string url, JToken body) { + return await client.GetResponseAsync(HttpRequest.Put(url, body)); + } + + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The body of the request. + /// The formatting to be used when serializing . + /// An instance of representing the raw response. + public static async Task PutAsync(this IHttpClientAsync client, string url, JToken body, Formatting formatting) { + return await client.GetResponseAsync(HttpRequest.Put(url, body, formatting)); + } + + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + public static async Task PutAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString, JToken body) { + return await client.GetResponseAsync(HttpRequest.Put(url, queryString, body)); + } + + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// The formatting to be used when serializing . + /// An instance of representing the raw response. + public static async Task PutAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString, JToken body, Formatting formatting) { + return await client.GetResponseAsync(HttpRequest.Put(url, queryString, body, formatting)); + } + + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The body of the request. + /// An instance of representing the raw response. + public static async Task PutAsync(this IHttpClientAsync client, string url, XNode body) { + return await client.GetResponseAsync(HttpRequest.Put(url, body)); + } + + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The body of the request. + /// The options to be used when serializing . + /// An instance of representing the raw response. + public static async Task PutAsync(this IHttpClientAsync client, string url, XNode body, SaveOptions options) { + return await client.GetResponseAsync(HttpRequest.Put(url, body, options)); + } + + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + public static async Task PutAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString, XNode body) { + return await client.GetResponseAsync(HttpRequest.Put(url, queryString, body)); + } + + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// The options to be used when serializing . + /// An instance of representing the raw response. + public static async Task PutAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString, XNode body, SaveOptions options) { + return await client.GetResponseAsync(HttpRequest.Put(url, queryString, body, options)); + } #if NAME_VALUE_COLLECTION - /// - /// Makes a DELETE request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// The query string of the request. - /// An instance of representing the response. - public static async Task DeleteAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return await client.GetResponseAsync(HttpRequest.Delete(url, query)); - } + /// + /// Makes a PUT request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// An instance of representing the raw response. + public static async Task PutAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return await client.GetResponseAsync(HttpRequest.Put(url, query)); + } + + /// + /// Makes a PUT request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// The query string of the request. + /// The POST data of the request. + /// An instance of representing the response. + public static async Task PutAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString, NameValueCollection? postData) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + IHttpPostData? post = postData == null ? null : new HttpPostData(postData); + return await client.GetResponseAsync(HttpRequest.Put(url, query, post)); + } + + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string of the request. + /// The content type of the request - eg. application/json. + /// The body of the request. + /// An instance of representing the response. + public static async Task PutAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString, string contentType, string body) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return await client.GetResponseAsync(HttpRequest.Put(url, query, contentType, body)); + } + + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + public static async Task PutAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString, JToken body) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return await client.GetResponseAsync(HttpRequest.Put(url, query, body)); + } + + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// The formatting to be used when serializing . + /// An instance of representing the raw response. + public static async Task PutAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString, JToken body, Formatting formatting) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return await client.GetResponseAsync(HttpRequest.Put(url, query, body, formatting)); + } + + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + public static async Task PutAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString, XNode body) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return await client.GetResponseAsync(HttpRequest.Put(url, query, body)); + } + + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// The options to be used when serializing . + /// An instance of representing the raw response. + public static async Task PutAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString, XNode body, SaveOptions options) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return await client.GetResponseAsync(HttpRequest.Put(url, query, body, options)); + } #endif - #endregion + #endregion + #region DeleteAsync(...) + + /// + /// Makes a HTTP DELETE request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// An instance of representing the response. + public static async Task DeleteAsync(this IHttpClientAsync client, string url) { + return await client.GetResponseAsync(HttpRequest.Delete(url)); + } + + /// + /// Makes a DELETE request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// The query string of the request. + /// An instance of representing the response. + public static async Task DeleteAsync(this IHttpClientAsync client, string url, IHttpQueryString? queryString) { + return await client.GetResponseAsync(HttpRequest.Delete(url, queryString)); + } + +#if NAME_VALUE_COLLECTION + + /// + /// Makes a DELETE request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// The query string of the request. + /// An instance of representing the response. + public static async Task DeleteAsync(this IHttpClientAsync client, string url, NameValueCollection? queryString) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return await client.GetResponseAsync(HttpRequest.Delete(url, query)); } +#endif + + #endregion + } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/Client/HttpClientExtensions.cs b/src/Skybrud.Essentials.Http/Client/HttpClientExtensions.cs index 15b2f83..83a4777 100644 --- a/src/Skybrud.Essentials.Http/Client/HttpClientExtensions.cs +++ b/src/Skybrud.Essentials.Http/Client/HttpClientExtensions.cs @@ -4,860 +4,858 @@ using System.Collections.Specialized; using System.Xml.Linq; -namespace Skybrud.Essentials.Http.Client { +namespace Skybrud.Essentials.Http.Client; - /// - /// Static class with various extension methods for . - /// - public static class HttpClientExtensions { +/// +/// Static class with various extension methods for . +/// +public static class HttpClientExtensions { - #region Get(...) + #region Get(...) - /// - /// Makes a HTTP GET request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// An instance of representing the response. - public static IHttpResponse Get(this IHttpClient client, string url) { - return client.GetResponse(HttpRequest.Get(url)); - } + /// + /// Makes a HTTP GET request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// An instance of representing the response. + public static IHttpResponse Get(this IHttpClient client, string url) { + return client.GetResponse(HttpRequest.Get(url)); + } - /// - /// Makes a GET request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// The query string of the request. - /// An instance of representing the response. - public static IHttpResponse Get(this IHttpClient client, string url, IHttpQueryString? queryString) { - return client.GetResponse(HttpRequest.Get(url, queryString)); - } + /// + /// Makes a GET request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// The query string of the request. + /// An instance of representing the response. + public static IHttpResponse Get(this IHttpClient client, string url, IHttpQueryString? queryString) { + return client.GetResponse(HttpRequest.Get(url, queryString)); + } #if NAME_VALUE_COLLECTION - /// - /// Makes a GET request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// The query string of the request. - /// An instance of representing the response. - public static IHttpResponse Get(this IHttpClient client, string url, NameValueCollection? queryString) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return client.GetResponse(HttpRequest.Get(url, query)); - } + /// + /// Makes a GET request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// The query string of the request. + /// An instance of representing the response. + public static IHttpResponse Get(this IHttpClient client, string url, NameValueCollection? queryString) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return client.GetResponse(HttpRequest.Get(url, query)); + } #endif - #endregion - - #region Post(...) - - /// - /// Makes a POST request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// An instance of representing the response. - public static IHttpResponse Post(this IHttpClient client, string url) { - return client.GetResponse(HttpRequest.Post(url)); - } - - /// - /// Makes a POST request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// An instance of representing the raw response. - public static IHttpResponse Post(this IHttpClient client, string url, IHttpQueryString? queryString) { - return client.GetResponse(HttpRequest.Post(url, queryString)); - } - - /// - /// Makes a POST request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// The POST data. - /// An instance of representing the raw response. - public static IHttpResponse Post(this IHttpClient client, string url, IHttpPostData? postData) { - return client.GetResponse(HttpRequest.Post(url, null, postData)); - } - - /// - /// Makes a POST request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// The query string of the request. - /// The POST data of the request. - /// An instance of representing the response. - public static IHttpResponse Post(this IHttpClient client, string url, IHttpQueryString? queryString, IHttpPostData? postData) { - return client.GetResponse(HttpRequest.Post(url, queryString, postData)); - } - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string of the request. - /// The content type of the request - eg. application/json. - /// The body of the request. - /// An instance of representing the response. - public static IHttpResponse Post(this IHttpClient client, string url, IHttpQueryString? queryString, string contentType, string body) { - return client.GetResponse(HttpRequest.Post(url, queryString, contentType, body)); - } - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The body of the request. - /// An instance of representing the raw response. - public static IHttpResponse Post(this IHttpClient client, string url, JToken body) { - return client.GetResponse(HttpRequest.Post(url, body)); - } - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The body of the request. - /// The formatting to be used when serializing . - /// An instance of representing the raw response. - public static IHttpResponse Post(this IHttpClient client, string url, JToken body, Formatting formatting) { - return client.GetResponse(HttpRequest.Post(url, body, formatting)); - } - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - public static IHttpResponse Post(this IHttpClient client, string url, IHttpQueryString? queryString, JToken body) { - return client.GetResponse(HttpRequest.Post(url, queryString, body)); - } - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// The formatting to be used when serializing . - /// An instance of representing the raw response. - public static IHttpResponse Post(this IHttpClient client, string url, IHttpQueryString? queryString, JToken body, Formatting formatting) { - return client.GetResponse(HttpRequest.Post(url, queryString, body, formatting)); - } - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The body of the request. - /// An instance of representing the raw response. - public static IHttpResponse Post(this IHttpClient client, string url, XNode body) { - return client.GetResponse(HttpRequest.Post(url, body)); - } - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The body of the request. - /// The options to be used when serializing . - /// An instance of representing the raw response. - public static IHttpResponse Post(this IHttpClient client, string url, XNode body, SaveOptions options) { - return client.GetResponse(HttpRequest.Post(url, body, options)); - } - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - public static IHttpResponse Post(this IHttpClient client, string url, IHttpQueryString? queryString, XNode body) { - return client.GetResponse(HttpRequest.Post(url, queryString, body)); - } - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// The options to be used when serializing . - /// An instance of representing the raw response. - public static IHttpResponse Post(this IHttpClient client, string url, IHttpQueryString? queryString, XNode body, SaveOptions options) { - return client.GetResponse(HttpRequest.Post(url, queryString, body, options)); - } + #endregion -#if NAME_VALUE_COLLECTION + #region Post(...) - /// - /// Makes a POST request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// An instance of representing the raw response. - public static IHttpResponse Post(this IHttpClient client, string url, NameValueCollection? queryString) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return client.GetResponse(HttpRequest.Post(url, query)); - } - - /// - /// Makes a POST request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// The query string of the request. - /// The POST data of the request. - /// An instance of representing the response. - public static IHttpResponse Post(this IHttpClient client, string url, NameValueCollection? queryString, NameValueCollection? postData) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - IHttpPostData? post = postData == null ? null : new HttpPostData(postData); - return client.GetResponse(HttpRequest.Post(url, query, post)); - } - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string of the request. - /// The content type of the request - eg. application/json. - /// The body of the request. - /// An instance of representing the response. - public static IHttpResponse Post(this IHttpClient client, string url, NameValueCollection? queryString, string contentType, string body) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return client.GetResponse(HttpRequest.Post(url, query, contentType, body)); - } - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - public static IHttpResponse Post(this IHttpClient client, string url, NameValueCollection? queryString, JToken body) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return client.GetResponse(HttpRequest.Post(url, query, body)); - } - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// The formatting to be used when serializing . - /// An instance of representing the raw response. - public static IHttpResponse Post(this IHttpClient client, string url, NameValueCollection? queryString, JToken body, Formatting formatting) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return client.GetResponse(HttpRequest.Post(url, query, body, formatting)); - } - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - public static IHttpResponse Post(this IHttpClient client, string url, NameValueCollection? queryString, XNode body) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return client.GetResponse(HttpRequest.Post(url, query, body)); - } - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// The options to be used when serializing . - /// An instance of representing the raw response. - public static IHttpResponse Post(this IHttpClient client, string url, NameValueCollection? queryString, XNode body, SaveOptions options) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return client.GetResponse(HttpRequest.Post(url, query, body, options)); - } + /// + /// Makes a POST request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// An instance of representing the response. + public static IHttpResponse Post(this IHttpClient client, string url) { + return client.GetResponse(HttpRequest.Post(url)); + } -#endif + /// + /// Makes a POST request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// An instance of representing the raw response. + public static IHttpResponse Post(this IHttpClient client, string url, IHttpQueryString? queryString) { + return client.GetResponse(HttpRequest.Post(url, queryString)); + } - #endregion - - #region Patch(...) - - /// - /// Makes a PATCH request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// An instance of representing the response. - public static IHttpResponse Patch(this IHttpClient client, string url) { - return client.GetResponse(HttpRequest.Patch(url)); - } - - /// - /// Makes a PATCH request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// An instance of representing the raw response. - public static IHttpResponse Patch(this IHttpClient client, string url, IHttpQueryString? queryString) { - return client.GetResponse(HttpRequest.Patch(url, queryString)); - } - - /// - /// Makes a PATCH request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// The POST data. - /// An instance of representing the raw response. - public static IHttpResponse Patch(this IHttpClient client, string url, IHttpPostData? postData) { - return client.GetResponse(HttpRequest.Patch(url, postData)); - } - - /// - /// Makes a PATCH request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// The query string of the request. - /// The POST data of the request. - /// An instance of representing the response. - public static IHttpResponse Patch(this IHttpClient client, string url, IHttpQueryString? queryString, IHttpPostData? postData) { - return client.GetResponse(HttpRequest.Patch(url, queryString, postData)); - } - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string of the request. - /// The content type of the request - eg. application/json. - /// The body of the request. - /// An instance of representing the response. - public static IHttpResponse Patch(this IHttpClient client, string url, IHttpQueryString? queryString, string? contentType, string? body) { - return client.GetResponse(HttpRequest.Patch(url, queryString, contentType, body)); - } - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The body of the request. - /// An instance of representing the raw response. - public static IHttpResponse Patch(this IHttpClient client, string url, JToken body) { - return client.GetResponse(HttpRequest.Patch(url, body)); - } - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The body of the request. - /// The formatting to be used when serializing . - /// An instance of representing the raw response. - public static IHttpResponse Patch(this IHttpClient client, string url, JToken body, Formatting formatting) { - return client.GetResponse(HttpRequest.Patch(url, body, formatting)); - } - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - public static IHttpResponse Patch(this IHttpClient client, string url, IHttpQueryString? queryString, JToken body) { - return client.GetResponse(HttpRequest.Patch(url, queryString, body)); - } - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// The formatting to be used when serializing . - /// An instance of representing the raw response. - public static IHttpResponse Patch(this IHttpClient client, string url, IHttpQueryString? queryString, JToken body, Formatting formatting) { - return client.GetResponse(HttpRequest.Patch(url, queryString, body, formatting)); - } - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The body of the request. - /// An instance of representing the raw response. - public static IHttpResponse Patch(this IHttpClient client, string url, XNode body) { - return client.GetResponse(HttpRequest.Patch(url, body)); - } - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The body of the request. - /// The options to be used when serializing . - /// An instance of representing the raw response. - public static IHttpResponse Patch(this IHttpClient client, string url, XNode body, SaveOptions options) { - return client.GetResponse(HttpRequest.Patch(url, body, options)); - } - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - public static IHttpResponse Patch(this IHttpClient client, string url, IHttpQueryString? queryString, XNode body) { - return client.GetResponse(HttpRequest.Patch(url, queryString, body)); - } - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// The options to be used when serializing . - /// An instance of representing the raw response. - public static IHttpResponse Patch(this IHttpClient client, string url, IHttpQueryString? queryString, XNode body, SaveOptions options) { - return client.GetResponse(HttpRequest.Patch(url, queryString, body, options)); - } + /// + /// Makes a POST request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// The POST data. + /// An instance of representing the raw response. + public static IHttpResponse Post(this IHttpClient client, string url, IHttpPostData? postData) { + return client.GetResponse(HttpRequest.Post(url, null, postData)); + } + + /// + /// Makes a POST request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// The query string of the request. + /// The POST data of the request. + /// An instance of representing the response. + public static IHttpResponse Post(this IHttpClient client, string url, IHttpQueryString? queryString, IHttpPostData? postData) { + return client.GetResponse(HttpRequest.Post(url, queryString, postData)); + } + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string of the request. + /// The content type of the request - eg. application/json. + /// The body of the request. + /// An instance of representing the response. + public static IHttpResponse Post(this IHttpClient client, string url, IHttpQueryString? queryString, string contentType, string body) { + return client.GetResponse(HttpRequest.Post(url, queryString, contentType, body)); + } + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The body of the request. + /// An instance of representing the raw response. + public static IHttpResponse Post(this IHttpClient client, string url, JToken body) { + return client.GetResponse(HttpRequest.Post(url, body)); + } + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The body of the request. + /// The formatting to be used when serializing . + /// An instance of representing the raw response. + public static IHttpResponse Post(this IHttpClient client, string url, JToken body, Formatting formatting) { + return client.GetResponse(HttpRequest.Post(url, body, formatting)); + } + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + public static IHttpResponse Post(this IHttpClient client, string url, IHttpQueryString? queryString, JToken body) { + return client.GetResponse(HttpRequest.Post(url, queryString, body)); + } + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// The formatting to be used when serializing . + /// An instance of representing the raw response. + public static IHttpResponse Post(this IHttpClient client, string url, IHttpQueryString? queryString, JToken body, Formatting formatting) { + return client.GetResponse(HttpRequest.Post(url, queryString, body, formatting)); + } + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The body of the request. + /// An instance of representing the raw response. + public static IHttpResponse Post(this IHttpClient client, string url, XNode body) { + return client.GetResponse(HttpRequest.Post(url, body)); + } + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The body of the request. + /// The options to be used when serializing . + /// An instance of representing the raw response. + public static IHttpResponse Post(this IHttpClient client, string url, XNode body, SaveOptions options) { + return client.GetResponse(HttpRequest.Post(url, body, options)); + } + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + public static IHttpResponse Post(this IHttpClient client, string url, IHttpQueryString? queryString, XNode body) { + return client.GetResponse(HttpRequest.Post(url, queryString, body)); + } + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// The options to be used when serializing . + /// An instance of representing the raw response. + public static IHttpResponse Post(this IHttpClient client, string url, IHttpQueryString? queryString, XNode body, SaveOptions options) { + return client.GetResponse(HttpRequest.Post(url, queryString, body, options)); + } #if NAME_VALUE_COLLECTION - /// - /// Makes a PATCH request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// An instance of representing the raw response. - public static IHttpResponse Patch(this IHttpClient client, string url, NameValueCollection? queryString) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return client.GetResponse(HttpRequest.Patch(url, query)); - } - - /// - /// Makes a PATCH request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// The query string of the request. - /// The POST data of the request. - /// An instance of representing the response. - public static IHttpResponse Patch(this IHttpClient client, string url, NameValueCollection? queryString, NameValueCollection? postData) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - IHttpPostData? post = postData == null ? null : new HttpPostData(postData); - return client.GetResponse(HttpRequest.Patch(url, query, post)); - } - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string of the request. - /// The content type of the request - eg. application/json. - /// The body of the request. - /// An instance of representing the response. - public static IHttpResponse Patch(this IHttpClient client, string url, NameValueCollection? queryString, string? contentType, string? body) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return client.GetResponse(HttpRequest.Patch(url, query, contentType, body)); - } - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - public static IHttpResponse Patch(this IHttpClient client, string url, NameValueCollection? queryString, JToken body) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return client.GetResponse(HttpRequest.Patch(url, query, body)); - } - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// The formatting to be used when serializing . - /// An instance of representing the raw response. - public static IHttpResponse Patch(this IHttpClient client, string url, NameValueCollection? queryString, JToken body, Formatting formatting) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return client.GetResponse(HttpRequest.Patch(url, query, body, formatting)); - } - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - public static IHttpResponse Patch(this IHttpClient client, string url, NameValueCollection? queryString, XNode body) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return client.GetResponse(HttpRequest.Patch(url, query, body)); - } - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// The options to be used when serializing . - /// An instance of representing the raw response. - public static IHttpResponse Patch(this IHttpClient client, string url, NameValueCollection? queryString, XNode body, SaveOptions options) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return client.GetResponse(HttpRequest.Patch(url, query, body, options)); - } + /// + /// Makes a POST request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// An instance of representing the raw response. + public static IHttpResponse Post(this IHttpClient client, string url, NameValueCollection? queryString) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return client.GetResponse(HttpRequest.Post(url, query)); + } + + /// + /// Makes a POST request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// The query string of the request. + /// The POST data of the request. + /// An instance of representing the response. + public static IHttpResponse Post(this IHttpClient client, string url, NameValueCollection? queryString, NameValueCollection? postData) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + IHttpPostData? post = postData == null ? null : new HttpPostData(postData); + return client.GetResponse(HttpRequest.Post(url, query, post)); + } + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string of the request. + /// The content type of the request - eg. application/json. + /// The body of the request. + /// An instance of representing the response. + public static IHttpResponse Post(this IHttpClient client, string url, NameValueCollection? queryString, string contentType, string body) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return client.GetResponse(HttpRequest.Post(url, query, contentType, body)); + } + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + public static IHttpResponse Post(this IHttpClient client, string url, NameValueCollection? queryString, JToken body) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return client.GetResponse(HttpRequest.Post(url, query, body)); + } + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// The formatting to be used when serializing . + /// An instance of representing the raw response. + public static IHttpResponse Post(this IHttpClient client, string url, NameValueCollection? queryString, JToken body, Formatting formatting) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return client.GetResponse(HttpRequest.Post(url, query, body, formatting)); + } + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + public static IHttpResponse Post(this IHttpClient client, string url, NameValueCollection? queryString, XNode body) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return client.GetResponse(HttpRequest.Post(url, query, body)); + } + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// The options to be used when serializing . + /// An instance of representing the raw response. + public static IHttpResponse Post(this IHttpClient client, string url, NameValueCollection? queryString, XNode body, SaveOptions options) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return client.GetResponse(HttpRequest.Post(url, query, body, options)); + } #endif - #endregion - - #region Put(...) - - /// - /// Makes a PUT request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// An instance of representing the response. - public static IHttpResponse Put(this IHttpClient client, string url) { - return client.GetResponse(HttpRequest.Put(url)); - } - - /// - /// Makes a PUT request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// An instance of representing the raw response. - public static IHttpResponse Put(this IHttpClient client, string url, IHttpQueryString? queryString) { - return client.GetResponse(HttpRequest.Put(url, queryString)); - } - - /// - /// Makes a PUT request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// The POST data. - /// An instance of representing the raw response. - public static IHttpResponse Put(this IHttpClient client, string url, IHttpPostData? postData) { - return client.GetResponse(HttpRequest.Put(url, postData)); - } - - /// - /// Makes a PUT request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// The query string of the request. - /// The POST data of the request. - /// An instance of representing the response. - public static IHttpResponse Put(this IHttpClient client, string url, IHttpQueryString? queryString, IHttpPostData? postData) { - return client.GetResponse(HttpRequest.Put(url, queryString, postData)); - } - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string of the request. - /// The content type of the request - eg. application/json. - /// The body of the request. - /// An instance of representing the response. - public static IHttpResponse Put(this IHttpClient client, string url, IHttpQueryString? queryString, string? contentType, string? body) { - return client.GetResponse(HttpRequest.Put(url, queryString, contentType, body)); - } - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The body of the request. - /// An instance of representing the raw response. - public static IHttpResponse Put(this IHttpClient client, string url, JToken body) { - return client.GetResponse(HttpRequest.Put(url, body)); - } - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The body of the request. - /// The formatting to be used when serializing . - /// An instance of representing the raw response. - public static IHttpResponse Put(this IHttpClient client, string url, JToken body, Formatting formatting) { - return client.GetResponse(HttpRequest.Put(url, body, formatting)); - } - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - public static IHttpResponse Put(this IHttpClient client, string url, IHttpQueryString? queryString, JToken body) { - return client.GetResponse(HttpRequest.Put(url, queryString, body)); - } - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// The formatting to be used when serializing . - /// An instance of representing the raw response. - public static IHttpResponse Put(this IHttpClient client, string url, IHttpQueryString? queryString, JToken body, Formatting formatting) { - return client.GetResponse(HttpRequest.Put(url, queryString, body, formatting)); - } - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The body of the request. - /// An instance of representing the raw response. - public static IHttpResponse Put(this IHttpClient client, string url, XNode body) { - return client.GetResponse(HttpRequest.Put(url, body)); - } - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The body of the request. - /// The options to be used when serializing . - /// An instance of representing the raw response. - public static IHttpResponse Put(this IHttpClient client, string url, XNode body, SaveOptions options) { - return client.GetResponse(HttpRequest.Put(url, body, options)); - } - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - public static IHttpResponse Put(this IHttpClient client, string url, IHttpQueryString? queryString, XNode body) { - return client.GetResponse(HttpRequest.Put(url, queryString, body)); - } - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// The options to be used when serializing . - /// An instance of representing the raw response. - public static IHttpResponse Put(this IHttpClient client, string url, IHttpQueryString? queryString, XNode body, SaveOptions options) { - return client.GetResponse(HttpRequest.Put(url, queryString, body, options)); - } + #endregion + + #region Patch(...) + + /// + /// Makes a PATCH request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// An instance of representing the response. + public static IHttpResponse Patch(this IHttpClient client, string url) { + return client.GetResponse(HttpRequest.Patch(url)); + } + + /// + /// Makes a PATCH request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// An instance of representing the raw response. + public static IHttpResponse Patch(this IHttpClient client, string url, IHttpQueryString? queryString) { + return client.GetResponse(HttpRequest.Patch(url, queryString)); + } + + /// + /// Makes a PATCH request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// The POST data. + /// An instance of representing the raw response. + public static IHttpResponse Patch(this IHttpClient client, string url, IHttpPostData? postData) { + return client.GetResponse(HttpRequest.Patch(url, postData)); + } + + /// + /// Makes a PATCH request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// The query string of the request. + /// The POST data of the request. + /// An instance of representing the response. + public static IHttpResponse Patch(this IHttpClient client, string url, IHttpQueryString? queryString, IHttpPostData? postData) { + return client.GetResponse(HttpRequest.Patch(url, queryString, postData)); + } + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string of the request. + /// The content type of the request - eg. application/json. + /// The body of the request. + /// An instance of representing the response. + public static IHttpResponse Patch(this IHttpClient client, string url, IHttpQueryString? queryString, string? contentType, string? body) { + return client.GetResponse(HttpRequest.Patch(url, queryString, contentType, body)); + } + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The body of the request. + /// An instance of representing the raw response. + public static IHttpResponse Patch(this IHttpClient client, string url, JToken body) { + return client.GetResponse(HttpRequest.Patch(url, body)); + } + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The body of the request. + /// The formatting to be used when serializing . + /// An instance of representing the raw response. + public static IHttpResponse Patch(this IHttpClient client, string url, JToken body, Formatting formatting) { + return client.GetResponse(HttpRequest.Patch(url, body, formatting)); + } + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + public static IHttpResponse Patch(this IHttpClient client, string url, IHttpQueryString? queryString, JToken body) { + return client.GetResponse(HttpRequest.Patch(url, queryString, body)); + } + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// The formatting to be used when serializing . + /// An instance of representing the raw response. + public static IHttpResponse Patch(this IHttpClient client, string url, IHttpQueryString? queryString, JToken body, Formatting formatting) { + return client.GetResponse(HttpRequest.Patch(url, queryString, body, formatting)); + } + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The body of the request. + /// An instance of representing the raw response. + public static IHttpResponse Patch(this IHttpClient client, string url, XNode body) { + return client.GetResponse(HttpRequest.Patch(url, body)); + } + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The body of the request. + /// The options to be used when serializing . + /// An instance of representing the raw response. + public static IHttpResponse Patch(this IHttpClient client, string url, XNode body, SaveOptions options) { + return client.GetResponse(HttpRequest.Patch(url, body, options)); + } + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + public static IHttpResponse Patch(this IHttpClient client, string url, IHttpQueryString? queryString, XNode body) { + return client.GetResponse(HttpRequest.Patch(url, queryString, body)); + } + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// The options to be used when serializing . + /// An instance of representing the raw response. + public static IHttpResponse Patch(this IHttpClient client, string url, IHttpQueryString? queryString, XNode body, SaveOptions options) { + return client.GetResponse(HttpRequest.Patch(url, queryString, body, options)); + } #if NAME_VALUE_COLLECTION - /// - /// Makes a PUT request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// An instance of representing the raw response. - public static IHttpResponse Put(this IHttpClient client, string url, NameValueCollection? queryString) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return client.GetResponse(HttpRequest.Put(url, query)); - } - - /// - /// Makes a PUT request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// The query string of the request. - /// The POST data of the request. - /// An instance of representing the response. - public static IHttpResponse Put(this IHttpClient client, string url, NameValueCollection? queryString, NameValueCollection? postData) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - IHttpPostData? post = postData == null ? null : new HttpPostData(postData); - return client.GetResponse(HttpRequest.Put(url, query, post)); - } - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string of the request. - /// The content type of the request - eg. application/json. - /// The body of the request. - /// An instance of representing the response. - public static IHttpResponse Put(this IHttpClient client, string url, NameValueCollection? queryString, string? contentType, string? body) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return client.GetResponse(HttpRequest.Put(url, query, contentType, body)); - } - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - public static IHttpResponse Put(this IHttpClient client, string url, NameValueCollection? queryString, JToken body) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return client.GetResponse(HttpRequest.Put(url, query, body)); - } - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// The formatting to be used when serializing . - /// An instance of representing the raw response. - public static IHttpResponse Put(this IHttpClient client, string url, NameValueCollection? queryString, JToken body, Formatting formatting) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return client.GetResponse(HttpRequest.Put(url, query, body, formatting)); - } - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - public static IHttpResponse Put(this IHttpClient client, string url, NameValueCollection? queryString, XNode body) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return client.GetResponse(HttpRequest.Put(url, query, body)); - } - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The HTTP client. - /// The URL of the request. - /// The query string. - /// The body of the request. - /// The options to be used when serializing . - /// An instance of representing the raw response. - public static IHttpResponse Put(this IHttpClient client, string url, NameValueCollection? queryString, XNode body, SaveOptions options) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return client.GetResponse(HttpRequest.Put(url, query, body, options)); - } + /// + /// Makes a PATCH request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// An instance of representing the raw response. + public static IHttpResponse Patch(this IHttpClient client, string url, NameValueCollection? queryString) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return client.GetResponse(HttpRequest.Patch(url, query)); + } + + /// + /// Makes a PATCH request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// The query string of the request. + /// The POST data of the request. + /// An instance of representing the response. + public static IHttpResponse Patch(this IHttpClient client, string url, NameValueCollection? queryString, NameValueCollection? postData) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + IHttpPostData? post = postData == null ? null : new HttpPostData(postData); + return client.GetResponse(HttpRequest.Patch(url, query, post)); + } + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string of the request. + /// The content type of the request - eg. application/json. + /// The body of the request. + /// An instance of representing the response. + public static IHttpResponse Patch(this IHttpClient client, string url, NameValueCollection? queryString, string? contentType, string? body) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return client.GetResponse(HttpRequest.Patch(url, query, contentType, body)); + } + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + public static IHttpResponse Patch(this IHttpClient client, string url, NameValueCollection? queryString, JToken body) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return client.GetResponse(HttpRequest.Patch(url, query, body)); + } + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// The formatting to be used when serializing . + /// An instance of representing the raw response. + public static IHttpResponse Patch(this IHttpClient client, string url, NameValueCollection? queryString, JToken body, Formatting formatting) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return client.GetResponse(HttpRequest.Patch(url, query, body, formatting)); + } + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + public static IHttpResponse Patch(this IHttpClient client, string url, NameValueCollection? queryString, XNode body) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return client.GetResponse(HttpRequest.Patch(url, query, body)); + } + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// The options to be used when serializing . + /// An instance of representing the raw response. + public static IHttpResponse Patch(this IHttpClient client, string url, NameValueCollection? queryString, XNode body, SaveOptions options) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return client.GetResponse(HttpRequest.Patch(url, query, body, options)); + } #endif - #endregion - - #region Delete(...) - - /// - /// Makes a HTTP DELETE request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// An instance of representing the response. - public static IHttpResponse Delete(this IHttpClient client, string url) { - return client.GetResponse(HttpRequest.Delete(url)); - } - - /// - /// Makes a DELETE request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// The query string of the request. - /// An instance of representing the response. - public static IHttpResponse Delete(this IHttpClient client, string url, IHttpQueryString? queryString) { - return client.GetResponse(HttpRequest.Delete(url, queryString)); - } + #endregion + + #region Put(...) + + /// + /// Makes a PUT request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// An instance of representing the response. + public static IHttpResponse Put(this IHttpClient client, string url) { + return client.GetResponse(HttpRequest.Put(url)); + } + + /// + /// Makes a PUT request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// An instance of representing the raw response. + public static IHttpResponse Put(this IHttpClient client, string url, IHttpQueryString? queryString) { + return client.GetResponse(HttpRequest.Put(url, queryString)); + } + + /// + /// Makes a PUT request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// The POST data. + /// An instance of representing the raw response. + public static IHttpResponse Put(this IHttpClient client, string url, IHttpPostData? postData) { + return client.GetResponse(HttpRequest.Put(url, postData)); + } + + /// + /// Makes a PUT request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// The query string of the request. + /// The POST data of the request. + /// An instance of representing the response. + public static IHttpResponse Put(this IHttpClient client, string url, IHttpQueryString? queryString, IHttpPostData? postData) { + return client.GetResponse(HttpRequest.Put(url, queryString, postData)); + } + + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string of the request. + /// The content type of the request - eg. application/json. + /// The body of the request. + /// An instance of representing the response. + public static IHttpResponse Put(this IHttpClient client, string url, IHttpQueryString? queryString, string? contentType, string? body) { + return client.GetResponse(HttpRequest.Put(url, queryString, contentType, body)); + } + + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The body of the request. + /// An instance of representing the raw response. + public static IHttpResponse Put(this IHttpClient client, string url, JToken body) { + return client.GetResponse(HttpRequest.Put(url, body)); + } + + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The body of the request. + /// The formatting to be used when serializing . + /// An instance of representing the raw response. + public static IHttpResponse Put(this IHttpClient client, string url, JToken body, Formatting formatting) { + return client.GetResponse(HttpRequest.Put(url, body, formatting)); + } + + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + public static IHttpResponse Put(this IHttpClient client, string url, IHttpQueryString? queryString, JToken body) { + return client.GetResponse(HttpRequest.Put(url, queryString, body)); + } + + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// The formatting to be used when serializing . + /// An instance of representing the raw response. + public static IHttpResponse Put(this IHttpClient client, string url, IHttpQueryString? queryString, JToken body, Formatting formatting) { + return client.GetResponse(HttpRequest.Put(url, queryString, body, formatting)); + } + + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The body of the request. + /// An instance of representing the raw response. + public static IHttpResponse Put(this IHttpClient client, string url, XNode body) { + return client.GetResponse(HttpRequest.Put(url, body)); + } + + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The body of the request. + /// The options to be used when serializing . + /// An instance of representing the raw response. + public static IHttpResponse Put(this IHttpClient client, string url, XNode body, SaveOptions options) { + return client.GetResponse(HttpRequest.Put(url, body, options)); + } + + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + public static IHttpResponse Put(this IHttpClient client, string url, IHttpQueryString? queryString, XNode body) { + return client.GetResponse(HttpRequest.Put(url, queryString, body)); + } + + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// The options to be used when serializing . + /// An instance of representing the raw response. + public static IHttpResponse Put(this IHttpClient client, string url, IHttpQueryString? queryString, XNode body, SaveOptions options) { + return client.GetResponse(HttpRequest.Put(url, queryString, body, options)); + } #if NAME_VALUE_COLLECTION - /// - /// Makes a DELETE request to the specified . - /// - /// The HTTP client. - /// The URL of the request. - /// The query string of the request. - /// An instance of representing the response. - public static IHttpResponse Delete(this IHttpClient client, string url, NameValueCollection? queryString) { - IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); - return client.GetResponse(HttpRequest.Delete(url, query)); - } + /// + /// Makes a PUT request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// An instance of representing the raw response. + public static IHttpResponse Put(this IHttpClient client, string url, NameValueCollection? queryString) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return client.GetResponse(HttpRequest.Put(url, query)); + } + + /// + /// Makes a PUT request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// The query string of the request. + /// The POST data of the request. + /// An instance of representing the response. + public static IHttpResponse Put(this IHttpClient client, string url, NameValueCollection? queryString, NameValueCollection? postData) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + IHttpPostData? post = postData == null ? null : new HttpPostData(postData); + return client.GetResponse(HttpRequest.Put(url, query, post)); + } + + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string of the request. + /// The content type of the request - eg. application/json. + /// The body of the request. + /// An instance of representing the response. + public static IHttpResponse Put(this IHttpClient client, string url, NameValueCollection? queryString, string? contentType, string? body) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return client.GetResponse(HttpRequest.Put(url, query, contentType, body)); + } + + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + public static IHttpResponse Put(this IHttpClient client, string url, NameValueCollection? queryString, JToken body) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return client.GetResponse(HttpRequest.Put(url, query, body)); + } + + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// The formatting to be used when serializing . + /// An instance of representing the raw response. + public static IHttpResponse Put(this IHttpClient client, string url, NameValueCollection? queryString, JToken body, Formatting formatting) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return client.GetResponse(HttpRequest.Put(url, query, body, formatting)); + } + + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + public static IHttpResponse Put(this IHttpClient client, string url, NameValueCollection? queryString, XNode body) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return client.GetResponse(HttpRequest.Put(url, query, body)); + } + + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The HTTP client. + /// The URL of the request. + /// The query string. + /// The body of the request. + /// The options to be used when serializing . + /// An instance of representing the raw response. + public static IHttpResponse Put(this IHttpClient client, string url, NameValueCollection? queryString, XNode body, SaveOptions options) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return client.GetResponse(HttpRequest.Put(url, query, body, options)); + } #endif - #endregion + #endregion + #region Delete(...) + + /// + /// Makes a HTTP DELETE request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// An instance of representing the response. + public static IHttpResponse Delete(this IHttpClient client, string url) { + return client.GetResponse(HttpRequest.Delete(url)); + } + + /// + /// Makes a DELETE request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// The query string of the request. + /// An instance of representing the response. + public static IHttpResponse Delete(this IHttpClient client, string url, IHttpQueryString? queryString) { + return client.GetResponse(HttpRequest.Delete(url, queryString)); + } + +#if NAME_VALUE_COLLECTION + + /// + /// Makes a DELETE request to the specified . + /// + /// The HTTP client. + /// The URL of the request. + /// The query string of the request. + /// An instance of representing the response. + public static IHttpResponse Delete(this IHttpClient client, string url, NameValueCollection? queryString) { + IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString); + return client.GetResponse(HttpRequest.Delete(url, query)); } +#endif + + #endregion + } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/Client/IHttpClient.cs b/src/Skybrud.Essentials.Http/Client/IHttpClient.cs index e917e1c..94ce11e 100644 --- a/src/Skybrud.Essentials.Http/Client/IHttpClient.cs +++ b/src/Skybrud.Essentials.Http/Client/IHttpClient.cs @@ -5,674 +5,672 @@ using Skybrud.Essentials.Http.Options; using System; -namespace Skybrud.Essentials.Http.Client { - - /// - /// Interface describing a client for making HTTP requests. - /// - public interface IHttpClient : IHttpClient2 { - - #region DoHttpGetRequest - - /// - /// Makes a HTTP GET request to the specified . - /// - /// The URL of the request. - /// An instance of representing the response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpGetRequest(string url); - - /// - /// Makes a GET request to the specified . - /// - /// The URL of the request. - /// The options for the call to the specified . - /// An instance of representing the response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpGetRequest(string url, IHttpGetOptions options); - - /// - /// Makes a GET request to the specified . - /// - /// The URL of the request. - /// The query string of the request. - /// An instance of representing the response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpGetRequest(string url, IHttpQueryString queryString); - - #endregion - - #region DoHttpPostRequest - - /// - /// Makes a POST request to the specified . - /// - /// The URL of the request. - /// An instance of representing the response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpPostRequest(string url); - - /// - /// Makes a POST request to the specified . - /// - /// The URL of the request. - /// The options for the call to the specified . - /// An instance of representing the response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpPostRequest(string url, IHttpGetOptions options); - - /// - /// Makes a POST request to the specified . - /// - /// The URL of the request. - /// The options for the call to the specified . - /// An instance of representing the response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpPostRequest(string url, IHttpPostOptions options); - - /// - /// Makes a POST request to the specified . - /// - /// The base URL of the request (no query string). - /// The query string. - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpPostRequest(string url, IHttpQueryString queryString); - - /// - /// Makes a POST request to the specified . - /// - /// The base URL of the request (no query string). - /// The POST data. - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpPostRequest(string url, IHttpPostData postData); - - /// - /// Makes a POST request to the specified . - /// - /// The URL of the request. - /// The query string of the request. - /// The POST data of the request. - /// An instance of representing the response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpPostRequest(string url, IHttpQueryString queryString, IHttpPostData postData); - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The URL of the request. - /// The query string of the request. - /// The content type of the request - eg. application/json. - /// The body of the request. - /// An instance of representing the response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpPostRequest(string url, IHttpQueryString queryString, string contentType, string body); - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The body of the request. - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpPostRequest(string url, JToken body); - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The body of the request. - /// The formatting to be used when serializing . - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpPostRequest(string url, JToken body, Formatting formatting); - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpPostRequest(string url, IHttpQueryString queryString, JToken body); - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// The formatting to be used when serializing . - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpPostRequest(string url, IHttpQueryString queryString, JToken body, Formatting formatting); - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The body of the request. - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpPostRequest(string url, XNode body); - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The body of the request. - /// The options to be used when serializing . - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpPostRequest(string url, XNode body, SaveOptions options); - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpPostRequest(string url, IHttpQueryString queryString, XNode body); - - /// - /// Makes a HTTP POST request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// The options to be used when serializing . - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpPostRequest(string url, IHttpQueryString queryString, XNode body, SaveOptions options); - - #endregion - - #region DoHttpPutRequest - - /// - /// Makes a PUT request to the specified . - /// - /// The URL of the request. - /// An instance of representing the response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpPutRequest(string url); - - /// - /// Makes a PUT request to the specified . - /// - /// The URL of the request. - /// The options for the call to the specified . - /// An instance of representing the response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpPutRequest(string url, IHttpGetOptions options); - - /// - /// Makes a PUT request to the specified . - /// - /// The URL of the request. - /// The options for the call to the specified . - /// An instance of representing the response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpPutRequest(string url, IHttpPostOptions options); - - /// - /// Makes a PUT request to the specified . - /// - /// The base URL of the request (no query string). - /// The query string. - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpPutRequest(string url, IHttpQueryString queryString); - - /// - /// Makes a PUT request to the specified . - /// - /// The base URL of the request (no query string). - /// The POST data. - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpPutRequest(string url, IHttpPostData postData); - - /// - /// Makes a PUT request to the specified . - /// - /// The URL of the request. - /// The query string of the request. - /// The POST data of the request. - /// An instance of representing the response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpPutRequest(string url, IHttpQueryString queryString, IHttpPostData postData); - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The URL of the request. - /// The query string of the request. - /// The content type of the request - eg. application/json. - /// The body of the request. - /// An instance of representing the response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpPutRequest(string url, IHttpQueryString queryString, string contentType, string body); - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The body of the request. - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpPutRequest(string url, JToken body); - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The body of the request. - /// The formatting to be used when serializing . - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpPutRequest(string url, JToken body, Formatting formatting); - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpPutRequest(string url, IHttpQueryString queryString, JToken body); - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// The formatting to be used when serializing . - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpPutRequest(string url, IHttpQueryString queryString, JToken body, Formatting formatting); - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The body of the request. - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpPutRequest(string url, XNode body); - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The body of the request. - /// The options to be used when serializing . - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpPutRequest(string url, XNode body, SaveOptions options); - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpPutRequest(string url, IHttpQueryString queryString, XNode body); - - /// - /// Makes a HTTP PUT request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// The options to be used when serializing . - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpPutRequest(string url, IHttpQueryString queryString, XNode body, SaveOptions options); - - #endregion - - #region DoHttpPatchRequest - - /// - /// Makes a PATCH request to the specified . - /// - /// The URL of the request. - /// An instance of representing the response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpPatchRequest(string url); - - /// - /// Makes a PATCH request to the specified . - /// - /// The URL of the request. - /// The options for the call to the specified . - /// An instance of representing the response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpPatchRequest(string url, IHttpGetOptions options); - - /// - /// Makes a PATCH request to the specified . - /// - /// The URL of the request. - /// The options for the call to the specified . - /// An instance of representing the response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpPatchRequest(string url, IHttpPostOptions options); - - /// - /// Makes a PATCH request to the specified . - /// - /// The base URL of the request (no query string). - /// The query string. - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpPatchRequest(string url, IHttpQueryString queryString); - - /// - /// Makes a PATCH request to the specified . - /// - /// The base URL of the request (no query string). - /// The POST data. - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpPatchRequest(string url, IHttpPostData postData); - - /// - /// Makes a PATCH request to the specified . - /// - /// The URL of the request. - /// The query string of the request. - /// The POST data of the request. - /// An instance of representing the response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpPatchRequest(string url, IHttpQueryString queryString, IHttpPostData postData); - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The URL of the request. - /// The query string of the request. - /// The content type of the request - eg. application/json. - /// The body of the request. - /// An instance of representing the response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpPatchRequest(string url, IHttpQueryString queryString, string contentType, string body); - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The body of the request. - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpPatchRequest(string url, JToken body); - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The body of the request. - /// The formatting to be used when serializing . - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpPatchRequest(string url, JToken body, Formatting formatting); - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpPatchRequest(string url, IHttpQueryString queryString, JToken body); - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// The formatting to be used when serializing . - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpPatchRequest(string url, IHttpQueryString queryString, JToken body, Formatting formatting); - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The body of the request. - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpPatchRequest(string url, XNode body); - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The body of the request. - /// The options to be used when serializing . - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpPatchRequest(string url, XNode body, SaveOptions options); - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpPatchRequest(string url, IHttpQueryString queryString, XNode body); - - /// - /// Makes a HTTP PATCH request based on the specified parameters. - /// - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// The options to be used when serializing . - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpPatchRequest(string url, IHttpQueryString queryString, XNode body, SaveOptions options); - - #endregion - - #region DoHttpDeleteRequest - - /// - /// Makes a HTTP DELETE request to the specified . - /// - /// The URL of the request. - /// An instance of representing the response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpDeleteRequest(string url); - - /// - /// Makes a DELETE request to the specified . - /// - /// The URL of the request. - /// The options for the call to the specified . - /// An instance of representing the response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpDeleteRequest(string url, IHttpGetOptions options); - - /// - /// Makes a DELETE request to the specified . - /// - /// The URL of the request. - /// The query string of the request. - /// An instance of representing the response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpDeleteRequest(string url, IHttpQueryString queryString); - - #endregion - - #region DoHttpRequest - - /// - /// Makes a HTTP request to the underlying API based on the specified parameters. - /// - /// The HTTP method of the request. - /// The base URL of the request (no query string). - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpRequest(HttpMethod method, string url); - - /// - /// Makes a HTTP request to the underlying API based on the specified parameters. - /// - /// The HTTP method of the request. - /// The base URL of the request (no query string). - /// The options for the call to the API. - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpGetOptions options); - - /// - /// Makes a HTTP request to the underlying API based on the specified parameters. - /// - /// The HTTP method of the request. - /// The base URL of the request (no query string). - /// The query string. - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpQueryString queryString); - - /// - /// Makes a HTTP request to the underlying API based on the specified parameters. - /// - /// The HTTP method of the request. - /// The base URL of the request (no query string). - /// The POST data. - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpPostData postData); - - /// - /// Makes a HTTP request to the underlying API based on the specified parameters. - /// - /// The HTTP method of the request. - /// The base URL of the request (no query string). - /// The query string. - /// The POST data. - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpQueryString queryString, IHttpPostData postData); - - /// - /// Makes a HTTP request to the underlying API based on the specified parameters. - /// - /// The HTTP method of the request. - /// The base URL of the request (no query string). - /// The query string. - /// The content type of the request - eg. application/json. - /// The body of the request. - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpQueryString queryString, string contentType, string body); - - /// - /// Makes a HTTP request based on the specified parameters. - /// - /// The HTTP method of the request. - /// The base URL of the request (no query string). - /// The body of the request. - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpRequest(HttpMethod method, string url, JToken body); - - /// - /// Makes a HTTP request based on the specified parameters. - /// - /// The HTTP method of the request. - /// The base URL of the request (no query string). - /// The body of the request. - /// The formatting to be used when serializing . - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpRequest(HttpMethod method, string url, JToken body, Formatting formatting); - - /// - /// Makes a HTTP request based on the specified parameters. - /// - /// The HTTP method of the request. - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpQueryString queryString, JToken body); - - /// - /// Makes a HTTP request based on the specified parameters. - /// - /// The HTTP method of the request. - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// The formatting to be used when serializing . - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpQueryString queryString, JToken body, Formatting formatting); - - /// - /// Makes a HTTP request based on the specified parameters. - /// - /// The HTTP method of the request. - /// The base URL of the request (no query string). - /// The body of the request. - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpRequest(HttpMethod method, string url, XNode body); - - /// - /// Makes a HTTP request based on the specified parameters. - /// - /// The HTTP method of the request. - /// The base URL of the request (no query string). - /// The body of the request. - /// The options to be used when serializing . - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpRequest(HttpMethod method, string url, XNode body, SaveOptions options); - - /// - /// Makes a HTTP request based on the specified parameters. - /// - /// The HTTP method of the request. - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpQueryString queryString, XNode body); - - /// - /// Makes a HTTP request based on the specified parameters. - /// - /// The HTTP method of the request. - /// The base URL of the request (no query string). - /// The query string. - /// The body of the request. - /// The options to be used when serializing . - /// An instance of representing the raw response. - [Obsolete("Don't use. Method will be removed in a future release.")] - IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpQueryString queryString, XNode body, SaveOptions options); - - #endregion - - } +namespace Skybrud.Essentials.Http.Client; + +/// +/// Interface describing a client for making HTTP requests. +/// +public interface IHttpClient : IHttpClient2 { + + #region DoHttpGetRequest + + /// + /// Makes a HTTP GET request to the specified . + /// + /// The URL of the request. + /// An instance of representing the response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpGetRequest(string url); + + /// + /// Makes a GET request to the specified . + /// + /// The URL of the request. + /// The options for the call to the specified . + /// An instance of representing the response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpGetRequest(string url, IHttpGetOptions options); + + /// + /// Makes a GET request to the specified . + /// + /// The URL of the request. + /// The query string of the request. + /// An instance of representing the response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpGetRequest(string url, IHttpQueryString queryString); + + #endregion + + #region DoHttpPostRequest + + /// + /// Makes a POST request to the specified . + /// + /// The URL of the request. + /// An instance of representing the response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpPostRequest(string url); + + /// + /// Makes a POST request to the specified . + /// + /// The URL of the request. + /// The options for the call to the specified . + /// An instance of representing the response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpPostRequest(string url, IHttpGetOptions options); + + /// + /// Makes a POST request to the specified . + /// + /// The URL of the request. + /// The options for the call to the specified . + /// An instance of representing the response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpPostRequest(string url, IHttpPostOptions options); + + /// + /// Makes a POST request to the specified . + /// + /// The base URL of the request (no query string). + /// The query string. + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpPostRequest(string url, IHttpQueryString queryString); + + /// + /// Makes a POST request to the specified . + /// + /// The base URL of the request (no query string). + /// The POST data. + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpPostRequest(string url, IHttpPostData postData); + + /// + /// Makes a POST request to the specified . + /// + /// The URL of the request. + /// The query string of the request. + /// The POST data of the request. + /// An instance of representing the response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpPostRequest(string url, IHttpQueryString queryString, IHttpPostData postData); + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The URL of the request. + /// The query string of the request. + /// The content type of the request - eg. application/json. + /// The body of the request. + /// An instance of representing the response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpPostRequest(string url, IHttpQueryString queryString, string contentType, string body); + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The body of the request. + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpPostRequest(string url, JToken body); + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The body of the request. + /// The formatting to be used when serializing . + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpPostRequest(string url, JToken body, Formatting formatting); + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpPostRequest(string url, IHttpQueryString queryString, JToken body); + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// The formatting to be used when serializing . + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpPostRequest(string url, IHttpQueryString queryString, JToken body, Formatting formatting); + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The body of the request. + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpPostRequest(string url, XNode body); + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The body of the request. + /// The options to be used when serializing . + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpPostRequest(string url, XNode body, SaveOptions options); + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpPostRequest(string url, IHttpQueryString queryString, XNode body); + + /// + /// Makes a HTTP POST request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// The options to be used when serializing . + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpPostRequest(string url, IHttpQueryString queryString, XNode body, SaveOptions options); + + #endregion + + #region DoHttpPutRequest + + /// + /// Makes a PUT request to the specified . + /// + /// The URL of the request. + /// An instance of representing the response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpPutRequest(string url); + + /// + /// Makes a PUT request to the specified . + /// + /// The URL of the request. + /// The options for the call to the specified . + /// An instance of representing the response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpPutRequest(string url, IHttpGetOptions options); + + /// + /// Makes a PUT request to the specified . + /// + /// The URL of the request. + /// The options for the call to the specified . + /// An instance of representing the response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpPutRequest(string url, IHttpPostOptions options); + + /// + /// Makes a PUT request to the specified . + /// + /// The base URL of the request (no query string). + /// The query string. + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpPutRequest(string url, IHttpQueryString queryString); + + /// + /// Makes a PUT request to the specified . + /// + /// The base URL of the request (no query string). + /// The POST data. + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpPutRequest(string url, IHttpPostData postData); + + /// + /// Makes a PUT request to the specified . + /// + /// The URL of the request. + /// The query string of the request. + /// The POST data of the request. + /// An instance of representing the response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpPutRequest(string url, IHttpQueryString queryString, IHttpPostData postData); + + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The URL of the request. + /// The query string of the request. + /// The content type of the request - eg. application/json. + /// The body of the request. + /// An instance of representing the response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpPutRequest(string url, IHttpQueryString queryString, string contentType, string body); + + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The body of the request. + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpPutRequest(string url, JToken body); + + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The body of the request. + /// The formatting to be used when serializing . + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpPutRequest(string url, JToken body, Formatting formatting); + + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpPutRequest(string url, IHttpQueryString queryString, JToken body); + + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// The formatting to be used when serializing . + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpPutRequest(string url, IHttpQueryString queryString, JToken body, Formatting formatting); + + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The body of the request. + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpPutRequest(string url, XNode body); + + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The body of the request. + /// The options to be used when serializing . + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpPutRequest(string url, XNode body, SaveOptions options); + + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpPutRequest(string url, IHttpQueryString queryString, XNode body); + + /// + /// Makes a HTTP PUT request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// The options to be used when serializing . + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpPutRequest(string url, IHttpQueryString queryString, XNode body, SaveOptions options); + + #endregion + + #region DoHttpPatchRequest + + /// + /// Makes a PATCH request to the specified . + /// + /// The URL of the request. + /// An instance of representing the response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpPatchRequest(string url); + + /// + /// Makes a PATCH request to the specified . + /// + /// The URL of the request. + /// The options for the call to the specified . + /// An instance of representing the response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpPatchRequest(string url, IHttpGetOptions options); + + /// + /// Makes a PATCH request to the specified . + /// + /// The URL of the request. + /// The options for the call to the specified . + /// An instance of representing the response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpPatchRequest(string url, IHttpPostOptions options); + + /// + /// Makes a PATCH request to the specified . + /// + /// The base URL of the request (no query string). + /// The query string. + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpPatchRequest(string url, IHttpQueryString queryString); + + /// + /// Makes a PATCH request to the specified . + /// + /// The base URL of the request (no query string). + /// The POST data. + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpPatchRequest(string url, IHttpPostData postData); + + /// + /// Makes a PATCH request to the specified . + /// + /// The URL of the request. + /// The query string of the request. + /// The POST data of the request. + /// An instance of representing the response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpPatchRequest(string url, IHttpQueryString queryString, IHttpPostData postData); + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The URL of the request. + /// The query string of the request. + /// The content type of the request - eg. application/json. + /// The body of the request. + /// An instance of representing the response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpPatchRequest(string url, IHttpQueryString queryString, string contentType, string body); + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The body of the request. + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpPatchRequest(string url, JToken body); + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The body of the request. + /// The formatting to be used when serializing . + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpPatchRequest(string url, JToken body, Formatting formatting); + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpPatchRequest(string url, IHttpQueryString queryString, JToken body); + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// The formatting to be used when serializing . + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpPatchRequest(string url, IHttpQueryString queryString, JToken body, Formatting formatting); + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The body of the request. + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpPatchRequest(string url, XNode body); + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The body of the request. + /// The options to be used when serializing . + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpPatchRequest(string url, XNode body, SaveOptions options); + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpPatchRequest(string url, IHttpQueryString queryString, XNode body); + + /// + /// Makes a HTTP PATCH request based on the specified parameters. + /// + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// The options to be used when serializing . + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpPatchRequest(string url, IHttpQueryString queryString, XNode body, SaveOptions options); + + #endregion + + #region DoHttpDeleteRequest + + /// + /// Makes a HTTP DELETE request to the specified . + /// + /// The URL of the request. + /// An instance of representing the response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpDeleteRequest(string url); + + /// + /// Makes a DELETE request to the specified . + /// + /// The URL of the request. + /// The options for the call to the specified . + /// An instance of representing the response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpDeleteRequest(string url, IHttpGetOptions options); + + /// + /// Makes a DELETE request to the specified . + /// + /// The URL of the request. + /// The query string of the request. + /// An instance of representing the response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpDeleteRequest(string url, IHttpQueryString queryString); + + #endregion + + #region DoHttpRequest + + /// + /// Makes a HTTP request to the underlying API based on the specified parameters. + /// + /// The HTTP method of the request. + /// The base URL of the request (no query string). + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpRequest(HttpMethod method, string url); + + /// + /// Makes a HTTP request to the underlying API based on the specified parameters. + /// + /// The HTTP method of the request. + /// The base URL of the request (no query string). + /// The options for the call to the API. + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpGetOptions options); + + /// + /// Makes a HTTP request to the underlying API based on the specified parameters. + /// + /// The HTTP method of the request. + /// The base URL of the request (no query string). + /// The query string. + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpQueryString queryString); + + /// + /// Makes a HTTP request to the underlying API based on the specified parameters. + /// + /// The HTTP method of the request. + /// The base URL of the request (no query string). + /// The POST data. + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpPostData postData); + + /// + /// Makes a HTTP request to the underlying API based on the specified parameters. + /// + /// The HTTP method of the request. + /// The base URL of the request (no query string). + /// The query string. + /// The POST data. + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpQueryString queryString, IHttpPostData postData); + + /// + /// Makes a HTTP request to the underlying API based on the specified parameters. + /// + /// The HTTP method of the request. + /// The base URL of the request (no query string). + /// The query string. + /// The content type of the request - eg. application/json. + /// The body of the request. + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpQueryString queryString, string contentType, string body); + + /// + /// Makes a HTTP request based on the specified parameters. + /// + /// The HTTP method of the request. + /// The base URL of the request (no query string). + /// The body of the request. + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpRequest(HttpMethod method, string url, JToken body); + + /// + /// Makes a HTTP request based on the specified parameters. + /// + /// The HTTP method of the request. + /// The base URL of the request (no query string). + /// The body of the request. + /// The formatting to be used when serializing . + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpRequest(HttpMethod method, string url, JToken body, Formatting formatting); + + /// + /// Makes a HTTP request based on the specified parameters. + /// + /// The HTTP method of the request. + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpQueryString queryString, JToken body); + + /// + /// Makes a HTTP request based on the specified parameters. + /// + /// The HTTP method of the request. + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// The formatting to be used when serializing . + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpQueryString queryString, JToken body, Formatting formatting); + + /// + /// Makes a HTTP request based on the specified parameters. + /// + /// The HTTP method of the request. + /// The base URL of the request (no query string). + /// The body of the request. + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpRequest(HttpMethod method, string url, XNode body); + + /// + /// Makes a HTTP request based on the specified parameters. + /// + /// The HTTP method of the request. + /// The base URL of the request (no query string). + /// The body of the request. + /// The options to be used when serializing . + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpRequest(HttpMethod method, string url, XNode body, SaveOptions options); + + /// + /// Makes a HTTP request based on the specified parameters. + /// + /// The HTTP method of the request. + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpQueryString queryString, XNode body); + + /// + /// Makes a HTTP request based on the specified parameters. + /// + /// The HTTP method of the request. + /// The base URL of the request (no query string). + /// The query string. + /// The body of the request. + /// The options to be used when serializing . + /// An instance of representing the raw response. + [Obsolete("Don't use. Method will be removed in a future release.")] + IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpQueryString queryString, XNode body, SaveOptions options); + + #endregion } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/Client/IHttpClient2.cs b/src/Skybrud.Essentials.Http/Client/IHttpClient2.cs index 23361e5..bb8cad8 100644 --- a/src/Skybrud.Essentials.Http/Client/IHttpClient2.cs +++ b/src/Skybrud.Essentials.Http/Client/IHttpClient2.cs @@ -1,26 +1,24 @@ using Skybrud.Essentials.Http.Options; -namespace Skybrud.Essentials.Http.Client { +namespace Skybrud.Essentials.Http.Client; + +/// +/// Interface describing a client for making HTTP requests. +/// +public interface IHttpClient2 { /// - /// Interface describing a client for making HTTP requests. + /// Returns the response of the request identified by the specified . /// - public interface IHttpClient2 { - - /// - /// Returns the response of the request identified by the specified . - /// - /// The options for the request to the API. - /// An instance of representing the raw response. - IHttpResponse GetResponse(IHttpRequestOptions options); - - /// - /// Sends a new request as described by and returns the response. - /// - /// An instance of describing the request. - /// An instance of representing the raw response. - IHttpResponse GetResponse(IHttpRequest request); + /// The options for the request to the API. + /// An instance of representing the raw response. + IHttpResponse GetResponse(IHttpRequestOptions options); - } + /// + /// Sends a new request as described by and returns the response. + /// + /// An instance of describing the request. + /// An instance of representing the raw response. + IHttpResponse GetResponse(IHttpRequest request); } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/Client/IHttpClientAsync.cs b/src/Skybrud.Essentials.Http/Client/IHttpClientAsync.cs index 60c124e..d2c777e 100644 --- a/src/Skybrud.Essentials.Http/Client/IHttpClientAsync.cs +++ b/src/Skybrud.Essentials.Http/Client/IHttpClientAsync.cs @@ -1,27 +1,25 @@ using Skybrud.Essentials.Http.Options; using System.Threading.Tasks; -namespace Skybrud.Essentials.Http.Client { +namespace Skybrud.Essentials.Http.Client; + +/// +/// Interface describing a client for making async HTTP requests. +/// +public interface IHttpClientAsync { /// - /// Interface describing a client for making async HTTP requests. + /// Sends a new request as described by and returns the response. /// - public interface IHttpClientAsync { - - /// - /// Sends a new request as described by and returns the response. - /// - /// An instance of describing the request. - /// An instance of representing the raw response. - Task GetResponseAsync(IHttpRequest request); - - /// - /// Executes the request and returns the corresponding response as an instance of . - /// - /// The options describing the request. - /// An instance of representing the response. - Task GetResponseAsync(IHttpRequestOptions options); + /// An instance of describing the request. + /// An instance of representing the raw response. + Task GetResponseAsync(IHttpRequest request); - } + /// + /// Executes the request and returns the corresponding response as an instance of . + /// + /// The options describing the request. + /// An instance of representing the response. + Task GetResponseAsync(IHttpRequestOptions options); } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/Collections/HttpCookieCollection.cs b/src/Skybrud.Essentials.Http/Collections/HttpCookieCollection.cs index 7397808..7985783 100644 --- a/src/Skybrud.Essentials.Http/Collections/HttpCookieCollection.cs +++ b/src/Skybrud.Essentials.Http/Collections/HttpCookieCollection.cs @@ -1,39 +1,37 @@ using System.Net; -namespace Skybrud.Essentials.Http.Collections { +namespace Skybrud.Essentials.Http.Collections; - /// - /// Collection of cookies. - /// - public class HttpCookieCollection : IHttpCookieCollection { - - #region Properties +/// +/// Collection of cookies. +/// +public class HttpCookieCollection : IHttpCookieCollection { - /// - /// Gets a reference to the internal instance of . - /// - public CookieContainer Container { get; private set; } + #region Properties - #endregion - - #region Constructors + /// + /// Gets a reference to the internal instance of . + /// + public CookieContainer Container { get; private set; } - /// - /// Creates an empty collection of headers. - /// - public HttpCookieCollection() { - Container = new CookieContainer(); - } + #endregion - /// - /// Creates a new instance based on the specified . - /// - public HttpCookieCollection(CookieContainer? cookies) { - Container = cookies ?? new CookieContainer(); - } + #region Constructors - #endregion + /// + /// Creates an empty collection of headers. + /// + public HttpCookieCollection() { + Container = new CookieContainer(); + } + /// + /// Creates a new instance based on the specified . + /// + public HttpCookieCollection(CookieContainer? cookies) { + Container = cookies ?? new CookieContainer(); } + #endregion + } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/Collections/HttpHeaderCollection.cs b/src/Skybrud.Essentials.Http/Collections/HttpHeaderCollection.cs index 48d10e5..f3999bb 100644 --- a/src/Skybrud.Essentials.Http/Collections/HttpHeaderCollection.cs +++ b/src/Skybrud.Essentials.Http/Collections/HttpHeaderCollection.cs @@ -4,158 +4,156 @@ using System.Linq; using System.Net; -namespace Skybrud.Essentials.Http.Collections { +namespace Skybrud.Essentials.Http.Collections; + +/// +/// Collection of HTTP headers. +/// +public class HttpHeaderCollection : IHttpHeaderCollection { + + #region Properties /// - /// Collection of HTTP headers. + /// Gets a reference to the internal instance of . /// - public class HttpHeaderCollection : IHttpHeaderCollection { - - #region Properties - - /// - /// Gets a reference to the internal instance of . - /// - public WebHeaderCollection Headers { get; } - - /// - /// Gets or sets the character sets that are acceptable - eg. utf8. This property corresponds to - /// the Accept-Charset HTTP header. - /// - public string? AcceptCharset { - get => Headers["Accept-Charset"]; - set => Headers["Accept-Charset"] = value; - } - - /// - /// Gets or sets the a list of acceptable encodings - eg. gzip or gzip, deflate. This - /// property corresponds to the Accept-Encoding HTTP header. - /// - /// - /// https://en.wikipedia.org/wiki/HTTP_compression - /// - public string? AcceptEncoding { - get => Headers["Accept-Encoding"]; - set => Headers["Accept-Encoding"] = value; - } - - /// - /// Gets or sets the accept language header of the request - eg. en-US, en or - /// da. This property corresponds to the Accept-Language HTTP header. - /// - /// - /// https://en.wikipedia.org/wiki/Content_negotiation - /// - public string? AcceptLanguage { - get => Headers["Accept-Language"]; - set => Headers["Accept-Language"] = value; - } - - /// - /// Gets or sets the authentication credentials for HTTP authentication. This property corresponds to the - /// Authorization HTTP header. - /// - public string? Authorization { - get => Headers["Authorization"]; - set => Headers["Authorization"] = value; - } - - /// - /// Gets amount of headers added to the collection. - /// - public int Count => Headers.Count; - - /// - /// Gets a array representing the keys of the header collection. - /// - public string[] Keys => Headers.AllKeys.ToArray(); - - /// - /// Gets or set the header with the specified . - /// - /// The key of the header. - /// The value of the header. - public string? this[string key] { - get => Headers[key]; - set => Headers[key] = value; - } - - #endregion - - #region Constructors - - /// - /// Creates an empty collection of headers. - /// - public HttpHeaderCollection() { - Headers = new WebHeaderCollection(); - } - - /// - /// Creates a new instance based on the specified . - /// - public HttpHeaderCollection(WebHeaderCollection? headers) { - Headers = headers ?? new WebHeaderCollection(); - } - - #endregion - - #region Member methods - - /// - /// Adds a new header with the specified and . - /// - /// The name of the header. - /// The value of the header. - public void Add(string name, string value) { - Headers[name] = value; - } - - /// - /// Adds a new header with the specified and . - /// - /// The name of the header. - /// The value of the header. - public void Add(string name, object value) { - Headers[name] = string.Format(CultureInfo.InvariantCulture, "{0}", value); - } - - - /// - /// Returns an enumerator that iterates through the collection. - /// - /// An enumerator that can be used to iterate through the collection. - public IEnumerator> GetEnumerator() { - return Headers.AllKeys.Select(x => new KeyValuePair(x, Headers[x]!)).GetEnumerator(); - } - - /// - /// Returns an enumerator that iterates through the collection. - /// - /// An enumerator that can be used to iterate through the collection. - IEnumerator IEnumerable.GetEnumerator() { - return GetEnumerator(); - } - - #endregion - - #region Operator overloading - - /// - /// Creates a new instance from the specified . - /// - /// The representing the headers. - public static implicit operator HttpHeaderCollection(WebHeaderCollection? headers) { - - // Initialize a new instance of HttpHeaderCollection - HttpHeaderCollection collection = new(headers); - - return collection; - - } - - #endregion + public WebHeaderCollection Headers { get; } + /// + /// Gets or sets the character sets that are acceptable - eg. utf8. This property corresponds to + /// the Accept-Charset HTTP header. + /// + public string? AcceptCharset { + get => Headers["Accept-Charset"]; + set => Headers["Accept-Charset"] = value; } + /// + /// Gets or sets the a list of acceptable encodings - eg. gzip or gzip, deflate. This + /// property corresponds to the Accept-Encoding HTTP header. + /// + /// + /// https://en.wikipedia.org/wiki/HTTP_compression + /// + public string? AcceptEncoding { + get => Headers["Accept-Encoding"]; + set => Headers["Accept-Encoding"] = value; + } + + /// + /// Gets or sets the accept language header of the request - eg. en-US, en or + /// da. This property corresponds to the Accept-Language HTTP header. + /// + /// + /// https://en.wikipedia.org/wiki/Content_negotiation + /// + public string? AcceptLanguage { + get => Headers["Accept-Language"]; + set => Headers["Accept-Language"] = value; + } + + /// + /// Gets or sets the authentication credentials for HTTP authentication. This property corresponds to the + /// Authorization HTTP header. + /// + public string? Authorization { + get => Headers["Authorization"]; + set => Headers["Authorization"] = value; + } + + /// + /// Gets amount of headers added to the collection. + /// + public int Count => Headers.Count; + + /// + /// Gets a array representing the keys of the header collection. + /// + public string[] Keys => Headers.AllKeys.ToArray(); + + /// + /// Gets or set the header with the specified . + /// + /// The key of the header. + /// The value of the header. + public string? this[string key] { + get => Headers[key]; + set => Headers[key] = value; + } + + #endregion + + #region Constructors + + /// + /// Creates an empty collection of headers. + /// + public HttpHeaderCollection() { + Headers = new WebHeaderCollection(); + } + + /// + /// Creates a new instance based on the specified . + /// + public HttpHeaderCollection(WebHeaderCollection? headers) { + Headers = headers ?? new WebHeaderCollection(); + } + + #endregion + + #region Member methods + + /// + /// Adds a new header with the specified and . + /// + /// The name of the header. + /// The value of the header. + public void Add(string name, string value) { + Headers[name] = value; + } + + /// + /// Adds a new header with the specified and . + /// + /// The name of the header. + /// The value of the header. + public void Add(string name, object value) { + Headers[name] = string.Format(CultureInfo.InvariantCulture, "{0}", value); + } + + + /// + /// Returns an enumerator that iterates through the collection. + /// + /// An enumerator that can be used to iterate through the collection. + public IEnumerator> GetEnumerator() { + return Headers.AllKeys.Select(x => new KeyValuePair(x, Headers[x]!)).GetEnumerator(); + } + + /// + /// Returns an enumerator that iterates through the collection. + /// + /// An enumerator that can be used to iterate through the collection. + IEnumerator IEnumerable.GetEnumerator() { + return GetEnumerator(); + } + + #endregion + + #region Operator overloading + + /// + /// Creates a new instance from the specified . + /// + /// The representing the headers. + public static implicit operator HttpHeaderCollection(WebHeaderCollection? headers) { + + // Initialize a new instance of HttpHeaderCollection + HttpHeaderCollection collection = new(headers); + + return collection; + + } + + #endregion + } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/Collections/HttpPostData.cs b/src/Skybrud.Essentials.Http/Collections/HttpPostData.cs index f711500..3183149 100644 --- a/src/Skybrud.Essentials.Http/Collections/HttpPostData.cs +++ b/src/Skybrud.Essentials.Http/Collections/HttpPostData.cs @@ -7,230 +7,228 @@ using System.Linq; using System.Text; -namespace Skybrud.Essentials.Http.Collections { +namespace Skybrud.Essentials.Http.Collections; - /// - /// Class representing the POST data of a HTTP request. - /// - public class HttpPostData : IHttpPostData { +/// +/// Class representing the POST data of a HTTP request. +/// +public class HttpPostData : IHttpPostData { - #region Private fields + #region Private fields - private readonly Dictionary _data; + private readonly Dictionary _data; - #endregion + #endregion - #region Properties + #region Properties - /// - /// Gets whether the request should be posted as multipart data. - /// - public bool IsMultipart { get; set; } + /// + /// Gets whether the request should be posted as multipart data. + /// + public bool IsMultipart { get; set; } - /// - /// Gets the amount of POST data entries. - /// - public int Count => _data.Count; + /// + /// Gets the amount of POST data entries. + /// + public int Count => _data.Count; - /// - /// Gets keys of all POST data entiries. - /// - public string[] Keys => _data.Keys.ToArray(); + /// + /// Gets keys of all POST data entiries. + /// + public string[] Keys => _data.Keys.ToArray(); - /// - /// Gets values of all POST data entiries. - /// - public Dictionary.ValueCollection Values => _data.Values; + /// + /// Gets values of all POST data entiries. + /// + public Dictionary.ValueCollection Values => _data.Values; - /// - /// Gets or sets the string value of the item with the specified . - /// - /// The key of the item. - /// The value of the item, or null if not found. - public string? this[string key] { - get => _data.TryGetValue(key, out IHttpPostValue? value) ? value.ToString() : null; - set => _data[key] = new HttpPostValue(key, value ?? string.Empty); - } + /// + /// Gets or sets the string value of the item with the specified . + /// + /// The key of the item. + /// The value of the item, or null if not found. + public string? this[string key] { + get => _data.TryGetValue(key, out IHttpPostValue? value) ? value.ToString() : null; + set => _data[key] = new HttpPostValue(key, value ?? string.Empty); + } - #endregion + #endregion - #region Constructors + #region Constructors - /// - /// Initializes an empty collection. - /// - public HttpPostData() { - _data = new Dictionary(); - } + /// + /// Initializes an empty collection. + /// + public HttpPostData() { + _data = new Dictionary(); + } #if NAME_VALUE_COLLECTION - /// - /// Initializes a new instance based on the specified . - /// - /// The collection the query string should be based. - public HttpPostData(NameValueCollection? collection) { - _data = new Dictionary(); - if (collection == null) return; - foreach (string key in collection.AllKeys) { - _data.Add(key, new HttpPostValue(key, collection[key])); - } + /// + /// Initializes a new instance based on the specified . + /// + /// The collection the query string should be based. + public HttpPostData(NameValueCollection? collection) { + _data = new Dictionary(); + if (collection == null) return; + foreach (string key in collection.AllKeys) { + _data.Add(key, new HttpPostValue(key, collection[key])); } + } #endif - #endregion + #endregion - #region Member methods + #region Member methods - /// - /// Returns whether the POST data contains an entry with the specified . - /// - /// The key of the entry. - /// true if the POST data contains an entry with the specified , - /// otherwise false. - public bool ContainsKey(string key) { - return _data.ContainsKey(key); - } + /// + /// Returns whether the POST data contains an entry with the specified . + /// + /// The key of the entry. + /// true if the POST data contains an entry with the specified , + /// otherwise false. + public bool ContainsKey(string key) { + return _data.ContainsKey(key); + } - /// - /// Adds an entry with the specified and . - /// - /// The key of the entry. - /// The value of the entry. - public void Add(string key, string value) { - _data.Add(key, new HttpPostValue(key, value)); - } + /// + /// Adds an entry with the specified and . + /// + /// The key of the entry. + /// The value of the entry. + public void Add(string key, string value) { + _data.Add(key, new HttpPostValue(key, value)); + } - /// - /// Adds an entry with the specified and . - /// - /// The key of the entry. - /// The value of the entry. - public void Add(string key, object value) { - _data.Add(key, new HttpPostValue(key, string.Format(CultureInfo.InvariantCulture, "{0}", value))); - } + /// + /// Adds an entry with the specified and . + /// + /// The key of the entry. + /// The value of the entry. + public void Add(string key, object value) { + _data.Add(key, new HttpPostValue(key, string.Format(CultureInfo.InvariantCulture, "{0}", value))); + } - /// - /// Adds a file entry with the specified and . - /// - /// The key of the entry. - /// The path to the file of the entry. - public void AddFile(string key, string path) { - _data.Add(key, new HttpPostFileValue(key, path)); - } + /// + /// Adds a file entry with the specified and . + /// + /// The key of the entry. + /// The path to the file of the entry. + public void AddFile(string key, string path) { + _data.Add(key, new HttpPostFileValue(key, path)); + } - /// - /// Adds a file entry with the specified , , - /// and . - /// - /// The key of the entry. - /// The path to the file of the entry. - /// The content type of the file. - /// The filename of the file. - public void AddFile(string key, string path, string contentType, string filename) { - _data.Add(key, new HttpPostFileValue(key, path, contentType, filename)); - } + /// + /// Adds a file entry with the specified , , + /// and . + /// + /// The key of the entry. + /// The path to the file of the entry. + /// The content type of the file. + /// The filename of the file. + public void AddFile(string key, string path, string contentType, string filename) { + _data.Add(key, new HttpPostFileValue(key, path, contentType, filename)); + } - /// - /// Sets the value of the entry with specified . If an entry with already - /// exists, it will be overwritten. - /// - /// The key of the entry. - /// The value of the entry. - public void Set(string key, string value) { - _data[key] = new HttpPostValue(key, value); - } + /// + /// Sets the value of the entry with specified . If an entry with already + /// exists, it will be overwritten. + /// + /// The key of the entry. + /// The value of the entry. + public void Set(string key, string value) { + _data[key] = new HttpPostValue(key, value); + } - /// - /// Sets the value of the entry with specified . If an entry with already - /// exists, it will be overwritten. - /// - /// The key of the entry. - /// The value of the entry. - public void Set(string key, object value) { - _data[key] = new HttpPostValue(key, string.Format(CultureInfo.InvariantCulture, "{0}", value)); - } + /// + /// Sets the value of the entry with specified . If an entry with already + /// exists, it will be overwritten. + /// + /// The key of the entry. + /// The value of the entry. + public void Set(string key, object value) { + _data[key] = new HttpPostValue(key, string.Format(CultureInfo.InvariantCulture, "{0}", value)); + } - /// - /// Removes the entry with the specified . - /// - /// The key of the entry. - public void Remove(string key) { - _data.Remove(key); - } + /// + /// Removes the entry with the specified . + /// + /// The key of the entry. + public void Remove(string key) { + _data.Remove(key); + } - /// - /// Gets whether the value with the specified is an instance of - /// . - /// - /// The key. - /// true if the item with the specified is an instance of - /// , otherwise false. - public bool IsFile(string key) { - return _data.TryGetValue(key, out IHttpPostValue? value) && value is HttpPostFileValue; - } + /// + /// Gets whether the value with the specified is an instance of + /// . + /// + /// The key. + /// true if the item with the specified is an instance of + /// , otherwise false. + public bool IsFile(string key) { + return _data.TryGetValue(key, out IHttpPostValue? value) && value is HttpPostFileValue; + } - internal static void Write(Stream stream, string str) { - byte[] bytes = Encoding.UTF8.GetBytes(str); - stream.Write(bytes, 0, bytes.Length); - } + internal static void Write(Stream stream, string str) { + byte[] bytes = Encoding.UTF8.GetBytes(str); + stream.Write(bytes, 0, bytes.Length); + } - /// - /// Writes the multipart POST data to the specified . - /// - /// The stream. - /// The multipart boundary. - public void WriteMultipartFormData(Stream stream, string boundary) { - int i = 0; - foreach (IHttpPostValue value in _data.Values) { - value.WriteToMultipartStream(stream, boundary, "\n", i++ == _data.Count - 1); - } + /// + /// Writes the multipart POST data to the specified . + /// + /// The stream. + /// The multipart boundary. + public void WriteMultipartFormData(Stream stream, string boundary) { + int i = 0; + foreach (IHttpPostValue value in _data.Values) { + value.WriteToMultipartStream(stream, boundary, "\n", i++ == _data.Count - 1); } + } - /// - /// Gets a string representation of the POST data. - /// - /// The POST data as an URL encoded string. - public override string ToString() { - return string.Join("&", _data.Select(pair => Uri.EscapeDataString(pair.Key) + "=" + Uri.EscapeDataString(pair.Value.ToString()!))); - } + /// + /// Gets a string representation of the POST data. + /// + /// The POST data as an URL encoded string. + public override string ToString() { + return string.Join("&", _data.Select(pair => Uri.EscapeDataString(pair.Key) + "=" + Uri.EscapeDataString(pair.Value.ToString()!))); + } - /// - /// Returns an enumerator that iterates through the collection. - /// - /// An enumerator that can be used to iterate through the collection. - public IEnumerator> GetEnumerator() { - return _data.Select(x => new KeyValuePair(x.Key, x.Value.ToString()!)).GetEnumerator(); - } + /// + /// Returns an enumerator that iterates through the collection. + /// + /// An enumerator that can be used to iterate through the collection. + public IEnumerator> GetEnumerator() { + return _data.Select(x => new KeyValuePair(x.Key, x.Value.ToString()!)).GetEnumerator(); + } - /// - /// Returns an enumerator that iterates through the collection. - /// - /// An enumerator that can be used to iterate through the collection. - IEnumerator IEnumerable.GetEnumerator() { - return GetEnumerator(); - } + /// + /// Returns an enumerator that iterates through the collection. + /// + /// An enumerator that can be used to iterate through the collection. + IEnumerator IEnumerable.GetEnumerator() { + return GetEnumerator(); + } - #endregion + #endregion - #region Operator overloading + #region Operator overloading #if NET_FRAMEWORK - /// - /// Initializes a new POST data collection based on the specified . - /// - /// The instance of the POST data should be based on. - /// An instance of based on the specified . - public static implicit operator HttpPostData(NameValueCollection? collection) { - return new HttpPostData(collection); - } + /// + /// Initializes a new POST data collection based on the specified . + /// + /// The instance of the POST data should be based on. + /// An instance of based on the specified . + public static implicit operator HttpPostData(NameValueCollection? collection) { + return new HttpPostData(collection); + } #endif - #endregion - - } + #endregion } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/Collections/HttpQueryString.cs b/src/Skybrud.Essentials.Http/Collections/HttpQueryString.cs index 04ec97d..1830c16 100644 --- a/src/Skybrud.Essentials.Http/Collections/HttpQueryString.cs +++ b/src/Skybrud.Essentials.Http/Collections/HttpQueryString.cs @@ -6,74 +6,74 @@ using System.Linq; using Skybrud.Essentials.Strings; -namespace Skybrud.Essentials.Http.Collections { +namespace Skybrud.Essentials.Http.Collections; - /// - /// Class representing a basic HTTP query string. - /// - public class HttpQueryString : IHttpQueryString { +/// +/// Class representing a basic HTTP query string. +/// +public class HttpQueryString : IHttpQueryString { - #region Private fields + #region Private fields - private readonly Dictionary _values; + private readonly Dictionary _values; - #endregion + #endregion - #region Properties + #region Properties - /// - /// Gets the number of key/value pairs contained in the internal dictionary instance. - /// - public int Count => _values.Count; + /// + /// Gets the number of key/value pairs contained in the internal dictionary instance. + /// + public int Count => _values.Count; - /// - /// Gets whether the internal dictionary is empty. - /// - public bool IsEmpty => _values.Count == 0; + /// + /// Gets whether the internal dictionary is empty. + /// + public bool IsEmpty => _values.Count == 0; - /// - /// Gets an array of the keys of all items in the query string. - /// - public string[] Keys => _values.Keys.ToArray(); + /// + /// Gets an array of the keys of all items in the query string. + /// + public string[] Keys => _values.Keys.ToArray(); - /// - /// Gets an array of all items in the query string. - /// - public KeyValuePair[] Items => _values.ToArray(); + /// + /// Gets an array of all items in the query string. + /// + public KeyValuePair[] Items => _values.ToArray(); - /// - /// Gets the value of the item with the specified . - /// - /// The key of the item to match. - /// The value of the item, or null if not found. - public string? this[string key] { - get => GetString(key); - set => Set(key, value); - } + /// + /// Gets the value of the item with the specified . + /// + /// The key of the item to match. + /// The value of the item, or null if not found. + public string? this[string key] { + get => GetString(key); + set => Set(key, value); + } - /// - /// Gets whether this implementation of supports duplicate keys. - /// - public bool SupportsDuplicateKeys => false; + /// + /// Gets whether this implementation of supports duplicate keys. + /// + public bool SupportsDuplicateKeys => false; - #endregion + #endregion - #region Constructors + #region Constructors - /// - /// Initializes a new instance without any entries. - /// - public HttpQueryString() { - _values = new Dictionary(); - } + /// + /// Initializes a new instance without any entries. + /// + public HttpQueryString() { + _values = new Dictionary(); + } - /// - /// Initializes a new instance based on the specified . - /// - /// The dictionary the query string should be based. - public HttpQueryString(Dictionary? dictionary) { - _values = dictionary ?? new Dictionary(); - } + /// + /// Initializes a new instance based on the specified . + /// + /// The dictionary the query string should be based. + public HttpQueryString(Dictionary? dictionary) { + _values = dictionary ?? new Dictionary(); + } #if NAME_VALUE_COLLECTION @@ -91,325 +91,325 @@ public HttpQueryString(NameValueCollection? collection) { #endif - #endregion - - #region Methods + #endregion - /// - /// Adds an entry with the specified and . - /// - /// The key of the entry. - /// The value of the entry. - public void Add(string key, object? value) { + #region Methods - if (string.IsNullOrWhiteSpace(key)) throw new ArgumentNullException(nameof(key)); + /// + /// Adds an entry with the specified and . + /// + /// The key of the entry. + /// The value of the entry. + public void Add(string key, object? value) { - // Abort if "value" is null - if (value == null) return; + if (string.IsNullOrWhiteSpace(key)) throw new ArgumentNullException(nameof(key)); - // Convert the value to a culture invariant string and add it to the dictionary - _values.Add(key, string.Format(CultureInfo.InvariantCulture, "{0}", value)); + // Abort if "value" is null + if (value == null) return; - } + // Convert the value to a culture invariant string and add it to the dictionary + _values.Add(key, string.Format(CultureInfo.InvariantCulture, "{0}", value)); - /// - /// Sets the of an entry with the specified . - /// - /// The key of the entry. - /// The value of the entry. - public void Set(string key, object? value) { - - if (string.IsNullOrWhiteSpace(key)) throw new ArgumentNullException(nameof(key)); - - // Specifying a null value should result in the item being removed - if (value == null) { - _values.Remove(key); - return; - } + } - // Convert the value to a culture invariant string and set it in the dictionary - _values[key] = string.Format(CultureInfo.InvariantCulture, "{0}", value); + /// + /// Sets the of an entry with the specified . + /// + /// The key of the entry. + /// The value of the entry. + public void Set(string key, object? value) { - } + if (string.IsNullOrWhiteSpace(key)) throw new ArgumentNullException(nameof(key)); - /// - /// Removes the value with the specified . - /// - /// The key of the element to remove. - /// true if the element is successfully found and removed; otherwise, false. This method returns false if is not found. - public bool Remove(string key) { - return _values.Remove(key); + // Specifying a null value should result in the item being removed + if (value == null) { + _values.Remove(key); + return; } - /// - /// Creates a copy of the . - /// - /// A copy of the . - public HttpQueryString Clone() { - return new HttpQueryString(new Dictionary(_values)); - } + // Convert the value to a culture invariant string and set it in the dictionary + _values[key] = string.Format(CultureInfo.InvariantCulture, "{0}", value); - /// - /// Creates a copy of the . - /// - /// A copy of the . - IHttpQueryString IHttpQueryString.Clone() { - return Clone(); - } + } - /// - /// Gets a string representation of the query string. - /// - /// The query string as an URL encoded string. - public override string ToString() { - return string.Join("&", from pair in _values select StringUtils.UrlEncode(pair.Key) + "=" + StringUtils.UrlEncode(pair.Value)); - } + /// + /// Removes the value with the specified . + /// + /// The key of the element to remove. + /// true if the element is successfully found and removed; otherwise, false. This method returns false if is not found. + public bool Remove(string key) { + return _values.Remove(key); + } - /// - /// Return whether the query string contains an entry with the specified . - /// - /// The key of the entry. - /// true if the query string contains the specified , otherwise - /// false. - public bool ContainsKey(string key) { - if (string.IsNullOrWhiteSpace(key)) throw new ArgumentNullException(nameof(key)); - return _values.ContainsKey(key); - } + /// + /// Creates a copy of the . + /// + /// A copy of the . + public HttpQueryString Clone() { + return new HttpQueryString(new Dictionary(_values)); + } - /// - /// Gets the value of the entry with the specified . - /// - /// The key of the entry. - /// The value of the entry, or null if not found. - public string? GetString(string key) { - if (string.IsNullOrWhiteSpace(key)) throw new ArgumentNullException(nameof(key)); - return _values.TryGetValue(key, out string? value) ? value : null; - } + /// + /// Creates a copy of the . + /// + /// A copy of the . + IHttpQueryString IHttpQueryString.Clone() { + return Clone(); + } - /// - /// Gets the value of the entry with the specified . - /// - /// The key of the entry. - /// The value of the entry, or 0 if not found. - public int GetInt32(string key) { - return GetValue(key); - } + /// + /// Gets a string representation of the query string. + /// + /// The query string as an URL encoded string. + public override string ToString() { + return string.Join("&", from pair in _values select StringUtils.UrlEncode(pair.Key) + "=" + StringUtils.UrlEncode(pair.Value)); + } - /// - /// Gets the value of the entry with the specified . - /// - /// The key of the entry. - /// The value of the entry, or 0 if not found. - public long GetInt64(string key) { - return GetValue(key); - } + /// + /// Return whether the query string contains an entry with the specified . + /// + /// The key of the entry. + /// true if the query string contains the specified , otherwise + /// false. + public bool ContainsKey(string key) { + if (string.IsNullOrWhiteSpace(key)) throw new ArgumentNullException(nameof(key)); + return _values.ContainsKey(key); + } - /// - /// Gets the value of the entry with the specified . - /// - /// The key of the entry. - /// The value of the entry, or 0 if not found. - public bool GetBoolean(string key) { - return GetValue(key); - } + /// + /// Gets the value of the entry with the specified . + /// + /// The key of the entry. + /// The value of the entry, or null if not found. + public string? GetString(string key) { + if (string.IsNullOrWhiteSpace(key)) throw new ArgumentNullException(nameof(key)); + return _values.TryGetValue(key, out string? value) ? value : null; + } - /// - /// Gets the value of the entry with the specified . - /// - /// The key of the entry. - /// The value of the entry, or 0 if not found. - public double GetDouble(string key) { - return GetValue(key); - } + /// + /// Gets the value of the entry with the specified . + /// + /// The key of the entry. + /// The value of the entry, or 0 if not found. + public int GetInt32(string key) { + return GetValue(key); + } - /// - /// Gets the value of the entry with the specified . - /// - /// The key of the entry. - /// The value of the entry, or 0 if not found. - public float GetFloat(string key) { - return GetValue(key); - } + /// + /// Gets the value of the entry with the specified . + /// + /// The key of the entry. + /// The value of the entry, or 0 if not found. + public long GetInt64(string key) { + return GetValue(key); + } - /// - /// Gets the value of the entry with the specified . - /// - /// The key of the entry. - /// The value of the entry, or the default value of if not found. - private T? GetValue(string key) { - if (string.IsNullOrWhiteSpace(key)) throw new ArgumentNullException(nameof(key)); - if (!_values.TryGetValue(key, out string? value)) return default; - return string.IsNullOrWhiteSpace(value) ? default : (T) Convert.ChangeType(value, typeof(T), CultureInfo.InvariantCulture); - } + /// + /// Gets the value of the entry with the specified . + /// + /// The key of the entry. + /// The value of the entry, or 0 if not found. + public bool GetBoolean(string key) { + return GetValue(key); + } - /// - /// Returns an enumerator that iterates through the collection. - /// - /// An enumerator that can be used to iterate through the collection. - public IEnumerator> GetEnumerator() { - return _values.GetEnumerator(); - } + /// + /// Gets the value of the entry with the specified . + /// + /// The key of the entry. + /// The value of the entry, or 0 if not found. + public double GetDouble(string key) { + return GetValue(key); + } - /// - /// Returns an enumerator that iterates through the collection. - /// - /// An enumerator that can be used to iterate through the collection. - IEnumerator IEnumerable.GetEnumerator() { - return GetEnumerator(); - } + /// + /// Gets the value of the entry with the specified . + /// + /// The key of the entry. + /// The value of the entry, or 0 if not found. + public float GetFloat(string key) { + return GetValue(key); + } - #endregion + /// + /// Gets the value of the entry with the specified . + /// + /// The key of the entry. + /// The value of the entry, or the default value of if not found. + private T? GetValue(string key) { + if (string.IsNullOrWhiteSpace(key)) throw new ArgumentNullException(nameof(key)); + if (!_values.TryGetValue(key, out string? value)) return default; + return string.IsNullOrWhiteSpace(value) ? default : (T) Convert.ChangeType(value, typeof(T), CultureInfo.InvariantCulture); + } - #region Static methods + /// + /// Returns an enumerator that iterates through the collection. + /// + /// An enumerator that can be used to iterate through the collection. + public IEnumerator> GetEnumerator() { + return _values.GetEnumerator(); + } - /// - /// Parses the specified query string into an instance of . - /// - /// The query string to parse. - /// An instance of . - [Obsolete("Use the 'Parse' method instead.")] - public static HttpQueryString ParseQueryString(string str) { - return Parse(str, true); - } + /// + /// Returns an enumerator that iterates through the collection. + /// + /// An enumerator that can be used to iterate through the collection. + IEnumerator IEnumerable.GetEnumerator() { + return GetEnumerator(); + } - /// - /// Parses the specified query string into an instance of . - /// - /// The query string to parse. - /// Whether the query string is URL encoded - /// An instance of representing the parsed query string. - /// - /// https://referencesource.microsoft.com/#System.Web/HttpValueCollection.cs,222f9a1bfd1f9a98,references - /// - [Obsolete("Use the 'Parse' method instead.")] - public static HttpQueryString ParseQueryString(string str, bool urlencoded) { - return Parse(str, urlencoded); - } + #endregion + #region Static methods - /// - /// Parses the specified query string into an instance of . - /// - /// The query string to parse. - /// An instance of . - public static HttpQueryString Parse(string str) { - return Parse(str, true); - } + /// + /// Parses the specified query string into an instance of . + /// + /// The query string to parse. + /// An instance of . + [Obsolete("Use the 'Parse' method instead.")] + public static HttpQueryString ParseQueryString(string str) { + return Parse(str, true); + } - /// - /// Parses the specified query string into an instance of . - /// - /// The query string to parse. - /// Whether the query string is URL encoded - /// An instance of representing the parsed query string. - /// - /// https://referencesource.microsoft.com/#System.Web/HttpValueCollection.cs,222f9a1bfd1f9a98,references - /// - public static HttpQueryString Parse(string str, bool urlencoded) { + /// + /// Parses the specified query string into an instance of . + /// + /// The query string to parse. + /// Whether the query string is URL encoded + /// An instance of representing the parsed query string. + /// + /// https://referencesource.microsoft.com/#System.Web/HttpValueCollection.cs,222f9a1bfd1f9a98,references + /// + [Obsolete("Use the 'Parse' method instead.")] + public static HttpQueryString ParseQueryString(string str, bool urlencoded) { + return Parse(str, urlencoded); + } - // Return an empty instance if "str" is NULL or empty - if (string.IsNullOrWhiteSpace(str)) return new HttpQueryString(); - Dictionary values = new(); + /// + /// Parses the specified query string into an instance of . + /// + /// The query string to parse. + /// An instance of . + public static HttpQueryString Parse(string str) { + return Parse(str, true); + } - int length = str.Length; + /// + /// Parses the specified query string into an instance of . + /// + /// The query string to parse. + /// Whether the query string is URL encoded + /// An instance of representing the parsed query string. + /// + /// https://referencesource.microsoft.com/#System.Web/HttpValueCollection.cs,222f9a1bfd1f9a98,references + /// + public static HttpQueryString Parse(string str, bool urlencoded) { - int i = 0; + // Return an empty instance if "str" is NULL or empty + if (string.IsNullOrWhiteSpace(str)) return new HttpQueryString(); - while (i < length) { + Dictionary values = new(); - int si = i; - int ti = -1; + int length = str.Length; - while (i < length) { - char ch = str[i]; + int i = 0; - if (ch == '=') { - if (ti < 0) - ti = i; - } else if (ch == '&') { - break; - } + while (i < length) { - i++; - } + int si = i; + int ti = -1; - // extract the name / value pair - string? name = null; - string value; + while (i < length) { + char ch = str[i]; - if (ti >= 0) { - name = str.Substring(si, ti - si); - value = str.Substring(ti + 1, i - ti - 1); - } else { - value = str.Substring(si, i - si); + if (ch == '=') { + if (ti < 0) + ti = i; + } else if (ch == '&') { + break; } - // TODO: Should we throw an exception if the key already exists? (I think Add might do it for us) + i++; + } - // add name / value pair to the collection - if (urlencoded) { - values.Add(StringUtils.UrlDecode(name) ?? string.Empty, StringUtils.UrlDecode(value)); - } else { - values.Add(name ?? string.Empty, value); - } + // extract the name / value pair + string? name = null; + string value; - // trailing '&' - if (i == length - 1 && str[i] == '&') { - values.Add(string.Empty, string.Empty); - } + if (ti >= 0) { + name = str.Substring(si, ti - si); + value = str.Substring(ti + 1, i - ti - 1); + } else { + value = str.Substring(si, i - si); + } - i++; + // TODO: Should we throw an exception if the key already exists? (I think Add might do it for us) + + // add name / value pair to the collection + if (urlencoded) { + values.Add(StringUtils.UrlDecode(name) ?? string.Empty, StringUtils.UrlDecode(value)); + } else { + values.Add(name ?? string.Empty, value); + } + // trailing '&' + if (i == length - 1 && str[i] == '&') { + values.Add(string.Empty, string.Empty); } - return new HttpQueryString(values); + i++; } + return new HttpQueryString(values); - /// - /// Converts the specified string representation of a query string to its - /// equivalent and returns a value that indicates whether the conversion succeeded. - /// - /// A string containing a query string to convert. - /// When this method returns, contains the value equivalent - /// to query string contained in , if the conversion succeeded, or null if the - /// conversion failed. This parameter is passed uninitialized. - /// true if the parameter was converted successfully; otherwise, false. - public bool TryParse(string str, out HttpQueryString? result) { - try { - result = Parse(str); - return true; - } catch { - result = null; - return false; - } + } + + + /// + /// Converts the specified string representation of a query string to its + /// equivalent and returns a value that indicates whether the conversion succeeded. + /// + /// A string containing a query string to convert. + /// When this method returns, contains the value equivalent + /// to query string contained in , if the conversion succeeded, or null if the + /// conversion failed. This parameter is passed uninitialized. + /// true if the parameter was converted successfully; otherwise, false. + public bool TryParse(string str, out HttpQueryString? result) { + try { + result = Parse(str); + return true; + } catch { + result = null; + return false; } + } - /// - /// Converts the specified string representation of a query string to its - /// equivalent and returns a value that indicates whether the conversion succeeded. - /// - /// A string containing a query string to convert. - /// When this method returns, contains the value equivalent - /// to query string contained in , if the conversion succeeded, or null if the - /// conversion failed. This parameter is passed uninitialized. - /// Whether the query string is URL encoded - /// true if the parameter was converted successfully; otherwise, false. - public bool TryParse(string str, bool urlencoded, out HttpQueryString? result) { - try { - result = Parse(str, urlencoded); - return true; - } catch { - result = null; - return false; - } + /// + /// Converts the specified string representation of a query string to its + /// equivalent and returns a value that indicates whether the conversion succeeded. + /// + /// A string containing a query string to convert. + /// When this method returns, contains the value equivalent + /// to query string contained in , if the conversion succeeded, or null if the + /// conversion failed. This parameter is passed uninitialized. + /// Whether the query string is URL encoded + /// true if the parameter was converted successfully; otherwise, false. + public bool TryParse(string str, bool urlencoded, out HttpQueryString? result) { + try { + result = Parse(str, urlencoded); + return true; + } catch { + result = null; + return false; } + } - #endregion + #endregion - #region Operator overloading + #region Operator overloading #if NET_FRAMEWORK @@ -424,8 +424,6 @@ public static implicit operator HttpQueryString(NameValueCollection? collection) #endif - #endregion - - } + #endregion } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/Collections/HttpQueryStringExtensions.cs b/src/Skybrud.Essentials.Http/Collections/HttpQueryStringExtensions.cs index 3937811..f18e169 100644 --- a/src/Skybrud.Essentials.Http/Collections/HttpQueryStringExtensions.cs +++ b/src/Skybrud.Essentials.Http/Collections/HttpQueryStringExtensions.cs @@ -3,99 +3,97 @@ using System.Diagnostics.CodeAnalysis; using System.Globalization; -namespace Skybrud.Essentials.Http.Collections { +namespace Skybrud.Essentials.Http.Collections; + +/// +/// Static class with various extension methods for . +/// +public static class HttpQueryStringExtensions { /// - /// Static class with various extension methods for . + /// Attempts to get the boolean value from the item in matching the specified . /// - public static class HttpQueryStringExtensions { - - /// - /// Attempts to get the boolean value from the item in matching the specified . - /// - /// The query string. - /// The key of the item. - /// When this method returns, contains the boolean value if successful; otherwise, false. - /// Whether the method was successful. - public static bool TryGetBoolean(this IHttpQueryString? query, string key, out bool result) { - if (string.IsNullOrWhiteSpace(key)) throw new ArgumentNullException(nameof(key)); - return StringUtils.TryParseBoolean(query?[key], out result); - } - - /// - /// Attempts to get the integer value from the item in matching the specified . - /// - /// The query string. - /// The key of the item. - /// When this method returns, contains the integer value if successful; otherwise, 0. - /// Whether the method was successful. - public static bool TryGetInt32(this IHttpQueryString? query, string key, out int result) { - if (string.IsNullOrWhiteSpace(key)) throw new ArgumentNullException(nameof(key)); - return int.TryParse(query?[key], NumberStyles.Any, CultureInfo.InvariantCulture, out result); - } + /// The query string. + /// The key of the item. + /// When this method returns, contains the boolean value if successful; otherwise, false. + /// Whether the method was successful. + public static bool TryGetBoolean(this IHttpQueryString? query, string key, out bool result) { + if (string.IsNullOrWhiteSpace(key)) throw new ArgumentNullException(nameof(key)); + return StringUtils.TryParseBoolean(query?[key], out result); + } - /// - /// Attempts to get the long value from the item in matching the specified . - /// - /// The query string. - /// The key of the item. - /// When this method returns, contains the long value if successful; otherwise, 0. - /// Whether the method was successful. - public static bool TryGetInt64(this IHttpQueryString? query, string key, out long result) { - if (string.IsNullOrWhiteSpace(key)) throw new ArgumentNullException(nameof(key)); - return long.TryParse(query?[key], NumberStyles.Any, CultureInfo.InvariantCulture, out result); + /// + /// Attempts to get the integer value from the item in matching the specified . + /// + /// The query string. + /// The key of the item. + /// When this method returns, contains the integer value if successful; otherwise, 0. + /// Whether the method was successful. + public static bool TryGetInt32(this IHttpQueryString? query, string key, out int result) { + if (string.IsNullOrWhiteSpace(key)) throw new ArgumentNullException(nameof(key)); + return int.TryParse(query?[key], NumberStyles.Any, CultureInfo.InvariantCulture, out result); + } - } + /// + /// Attempts to get the long value from the item in matching the specified . + /// + /// The query string. + /// The key of the item. + /// When this method returns, contains the long value if successful; otherwise, 0. + /// Whether the method was successful. + public static bool TryGetInt64(this IHttpQueryString? query, string key, out long result) { + if (string.IsNullOrWhiteSpace(key)) throw new ArgumentNullException(nameof(key)); + return long.TryParse(query?[key], NumberStyles.Any, CultureInfo.InvariantCulture, out result); - /// - /// Attempts to get the float value from the item in matching the specified . - /// - /// The query string. - /// The key of the item. - /// When this method returns, contains the float value if successful; otherwise, 0. - /// Whether the method was successful. - public static bool TryGetFloat(this IHttpQueryString? query, string key, out float result) { - if (string.IsNullOrWhiteSpace(key)) throw new ArgumentNullException(nameof(key)); - return float.TryParse(query?[key], NumberStyles.Any, CultureInfo.InvariantCulture, out result); - } + } - /// - /// Attempts to get the float value from the item in matching the specified . - /// - /// The query string. - /// The key of the item. - /// When this method returns, contains the float value if successful; otherwise, 0. - /// Whether the method was successful. - public static bool TryGetSingle(this IHttpQueryString? query, string key, out float result) { - if (string.IsNullOrWhiteSpace(key)) throw new ArgumentNullException(nameof(key)); - return float.TryParse(query?[key], NumberStyles.Any, CultureInfo.InvariantCulture, out result); - } + /// + /// Attempts to get the float value from the item in matching the specified . + /// + /// The query string. + /// The key of the item. + /// When this method returns, contains the float value if successful; otherwise, 0. + /// Whether the method was successful. + public static bool TryGetFloat(this IHttpQueryString? query, string key, out float result) { + if (string.IsNullOrWhiteSpace(key)) throw new ArgumentNullException(nameof(key)); + return float.TryParse(query?[key], NumberStyles.Any, CultureInfo.InvariantCulture, out result); + } - /// - /// Attempts to get the double value from the item in matching the specified . - /// - /// The query string. - /// The key of the item. - /// When this method returns, contains the double value if successful; otherwise, 0. - /// Whether the method was successful. - public static bool TryGetDouble(this IHttpQueryString? query, string key, out double result) { - if (string.IsNullOrWhiteSpace(key)) throw new ArgumentNullException(nameof(key)); - return double.TryParse(query?[key], NumberStyles.Any, CultureInfo.InvariantCulture, out result); - } + /// + /// Attempts to get the float value from the item in matching the specified . + /// + /// The query string. + /// The key of the item. + /// When this method returns, contains the float value if successful; otherwise, 0. + /// Whether the method was successful. + public static bool TryGetSingle(this IHttpQueryString? query, string key, out float result) { + if (string.IsNullOrWhiteSpace(key)) throw new ArgumentNullException(nameof(key)); + return float.TryParse(query?[key], NumberStyles.Any, CultureInfo.InvariantCulture, out result); + } - /// - /// Attempts to get the string value from the item in matching the specified . - /// - /// The query string. - /// The key of the item. - /// When this method returns, contains the string value if successful; otherwise, null. - /// Whether the method was successful. - public static bool TryGetString(this IHttpQueryString? query, string key, [NotNullWhen(true)] out string? result) { - if (string.IsNullOrWhiteSpace(key)) throw new ArgumentNullException(nameof(key)); - result = query?[key]; - return result != null; - } + /// + /// Attempts to get the double value from the item in matching the specified . + /// + /// The query string. + /// The key of the item. + /// When this method returns, contains the double value if successful; otherwise, 0. + /// Whether the method was successful. + public static bool TryGetDouble(this IHttpQueryString? query, string key, out double result) { + if (string.IsNullOrWhiteSpace(key)) throw new ArgumentNullException(nameof(key)); + return double.TryParse(query?[key], NumberStyles.Any, CultureInfo.InvariantCulture, out result); + } + /// + /// Attempts to get the string value from the item in matching the specified . + /// + /// The query string. + /// The key of the item. + /// When this method returns, contains the string value if successful; otherwise, null. + /// Whether the method was successful. + public static bool TryGetString(this IHttpQueryString? query, string key, [NotNullWhen(true)] out string? result) { + if (string.IsNullOrWhiteSpace(key)) throw new ArgumentNullException(nameof(key)); + result = query?[key]; + return result != null; } } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/Collections/IHttpCookieCollection.cs b/src/Skybrud.Essentials.Http/Collections/IHttpCookieCollection.cs index b1702d7..366261f 100644 --- a/src/Skybrud.Essentials.Http/Collections/IHttpCookieCollection.cs +++ b/src/Skybrud.Essentials.Http/Collections/IHttpCookieCollection.cs @@ -1,21 +1,19 @@ using System.Net; -namespace Skybrud.Essentials.Http.Collections { +namespace Skybrud.Essentials.Http.Collections; - /// - /// Interface describing a collection of cookies. - /// - public interface IHttpCookieCollection { - - #region Properties +/// +/// Interface describing a collection of cookies. +/// +public interface IHttpCookieCollection { - /// - /// Gets a reference to the internal instance of . - /// - CookieContainer Container { get; } + #region Properties - #endregion + /// + /// Gets a reference to the internal instance of . + /// + CookieContainer Container { get; } - } + #endregion } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/Collections/IHttpHeaderCollection.cs b/src/Skybrud.Essentials.Http/Collections/IHttpHeaderCollection.cs index e086d64..cfe8f2a 100644 --- a/src/Skybrud.Essentials.Http/Collections/IHttpHeaderCollection.cs +++ b/src/Skybrud.Essentials.Http/Collections/IHttpHeaderCollection.cs @@ -1,87 +1,85 @@ using System.Collections.Generic; using System.Net; -namespace Skybrud.Essentials.Http.Collections { +namespace Skybrud.Essentials.Http.Collections; + +/// +/// Interface describing a collection of HTTP headers. +/// +public interface IHttpHeaderCollection : IEnumerable> { + + #region Properties + + /// + /// Gets a reference to the internal instance of . + /// + WebHeaderCollection Headers { get; } + + /// + /// Gets or sets the character sets that are acceptable - eg. utf8. This property corresponds to + /// the Accept-Charset HTTP header. + /// + string? AcceptCharset { get; set; } + + /// + /// Gets or sets the a list of acceptable encodings - eg. gzip or gzip, deflate. This + /// property corresponds to the Accept-Encoding HTTP header. + /// + /// + /// https://en.wikipedia.org/wiki/HTTP_compression + /// + string? AcceptEncoding { get; set; } + + /// + /// Gets or sets the accept language header of the request - eg. en-US, en or + /// da. This property corresponds to the Accept-Language HTTP header. + /// + /// + /// https://en.wikipedia.org/wiki/Content_negotiation + /// + string? AcceptLanguage { get; set; } + + /// + /// Gets or sets the authentication credentials for HTTP authentication. This property corresponds to the + /// Authorization HTTP header. + /// + string? Authorization { get; set; } + + /// + /// Gets amount of headers added to the collection. + /// + int Count { get; } + + /// + /// Gets a array representing the keys of the header collection. + /// + string[] Keys { get; } + + /// + /// Gets or set the header with the specified . + /// + /// The key of the header. + /// The value of the header. + string? this[string key] { get; set; } + + #endregion + + #region Methods /// - /// Interface describing a collection of HTTP headers. + /// Adds a new header with the specified and . /// - public interface IHttpHeaderCollection : IEnumerable> { - - #region Properties - - /// - /// Gets a reference to the internal instance of . - /// - WebHeaderCollection Headers { get; } - - /// - /// Gets or sets the character sets that are acceptable - eg. utf8. This property corresponds to - /// the Accept-Charset HTTP header. - /// - string? AcceptCharset { get; set; } - - /// - /// Gets or sets the a list of acceptable encodings - eg. gzip or gzip, deflate. This - /// property corresponds to the Accept-Encoding HTTP header. - /// - /// - /// https://en.wikipedia.org/wiki/HTTP_compression - /// - string? AcceptEncoding { get; set; } - - /// - /// Gets or sets the accept language header of the request - eg. en-US, en or - /// da. This property corresponds to the Accept-Language HTTP header. - /// - /// - /// https://en.wikipedia.org/wiki/Content_negotiation - /// - string? AcceptLanguage { get; set; } - - /// - /// Gets or sets the authentication credentials for HTTP authentication. This property corresponds to the - /// Authorization HTTP header. - /// - string? Authorization { get; set; } - - /// - /// Gets amount of headers added to the collection. - /// - int Count { get; } - - /// - /// Gets a array representing the keys of the header collection. - /// - string[] Keys { get; } - - /// - /// Gets or set the header with the specified . - /// - /// The key of the header. - /// The value of the header. - string? this[string key] { get; set; } - - #endregion - - #region Methods - - /// - /// Adds a new header with the specified and . - /// - /// The name of the header. - /// The value of the header. - void Add(string name, string value); - - /// - /// Adds a new header with the specified and . - /// - /// The name of the header. - /// The value of the header. - void Add(string name, object value); - - #endregion - - } + /// The name of the header. + /// The value of the header. + void Add(string name, string value); + + /// + /// Adds a new header with the specified and . + /// + /// The name of the header. + /// The value of the header. + void Add(string name, object value); + + #endregion } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/Collections/IHttpPostData.cs b/src/Skybrud.Essentials.Http/Collections/IHttpPostData.cs index 11af5d7..ce80038 100644 --- a/src/Skybrud.Essentials.Http/Collections/IHttpPostData.cs +++ b/src/Skybrud.Essentials.Http/Collections/IHttpPostData.cs @@ -1,124 +1,122 @@ using System.Collections.Generic; using System.IO; -namespace Skybrud.Essentials.Http.Collections { +namespace Skybrud.Essentials.Http.Collections; + +/// +/// Interface describing the request body of a HTTP POST request. +/// +public interface IHttpPostData : IEnumerable> { + + #region Properties + + /// + /// Gets whether the request should be posted as multipart data. + /// + bool IsMultipart { get; } + + /// + /// Gets the amount of POST data entries. + /// + int Count { get; } + + /// + /// Gets an array of the keys of all POST data entiries. + /// + string[] Keys { get; } + + /// + /// Gets values of all POST data entiries. + /// + Dictionary.ValueCollection Values { get; } + + /// + /// Gets or sets the string value of the item with the specified . + /// + /// The key of the item. + /// The value of the item, or null if not found. + string? this[string key] { get; set; } + + #endregion + + #region Member methods + + /// + /// Returns whether the POST data contains an entry with the specified . + /// + /// The key of the entry. + /// true if the POST data contains an entry with the specified , + /// otherwise false. + bool ContainsKey(string key); /// - /// Interface describing the request body of a HTTP POST request. + /// Adds an entry with the specified and . /// - public interface IHttpPostData : IEnumerable> { - - #region Properties - - /// - /// Gets whether the request should be posted as multipart data. - /// - bool IsMultipart { get; } - - /// - /// Gets the amount of POST data entries. - /// - int Count { get; } - - /// - /// Gets an array of the keys of all POST data entiries. - /// - string[] Keys { get; } - - /// - /// Gets values of all POST data entiries. - /// - Dictionary.ValueCollection Values { get; } - - /// - /// Gets or sets the string value of the item with the specified . - /// - /// The key of the item. - /// The value of the item, or null if not found. - string? this[string key] { get; set; } - - #endregion - - #region Member methods - - /// - /// Returns whether the POST data contains an entry with the specified . - /// - /// The key of the entry. - /// true if the POST data contains an entry with the specified , - /// otherwise false. - bool ContainsKey(string key); - - /// - /// Adds an entry with the specified and . - /// - /// The key of the entry. - /// The value of the entry. - void Add(string key, string value); - - /// - /// Adds an entry with the specified and . - /// - /// The key of the entry. - /// The value of the entry. - void Add(string key, object value); - - /// - /// Adds a file entry with the specified and . - /// - /// The key of the entry. - /// The path to the file of the entry. - void AddFile(string key, string path); - - /// - /// Adds a file entry with the specified , , - /// and . - /// - /// The key of the entry. - /// The path to the file of the entry. - /// The content type of the file. - /// The filename of the file. - void AddFile(string key, string path, string contentType, string filename); - - /// - /// Sets the value of the entry with specified . If an entry with - /// already exists, it will be overwritten. - /// - /// The key of the entry. - /// The value of the entry. - void Set(string key, string value); - - /// - /// Sets the value of the entry with specified . If an entry with - /// already exists, it will be overwritten. - /// - /// The key of the entry. - /// The value of the entry. - void Set(string key, object value); - - /// - /// Removes the entry with the specified . - /// - /// The key of the entry. - void Remove(string key); - - /// - /// Gets whether the value with the specified key is an instance of . - /// - /// The key. - /// true if the item with the specified is an instance of - /// , otherwise false. - bool IsFile(string key); - - /// - /// Writes the multipart POST data to the specified stream. - /// - /// The stream. - /// The multipart boundary. - void WriteMultipartFormData(Stream stream, string boundary); - - #endregion - - } + /// The key of the entry. + /// The value of the entry. + void Add(string key, string value); + + /// + /// Adds an entry with the specified and . + /// + /// The key of the entry. + /// The value of the entry. + void Add(string key, object value); + + /// + /// Adds a file entry with the specified and . + /// + /// The key of the entry. + /// The path to the file of the entry. + void AddFile(string key, string path); + + /// + /// Adds a file entry with the specified , , + /// and . + /// + /// The key of the entry. + /// The path to the file of the entry. + /// The content type of the file. + /// The filename of the file. + void AddFile(string key, string path, string contentType, string filename); + + /// + /// Sets the value of the entry with specified . If an entry with + /// already exists, it will be overwritten. + /// + /// The key of the entry. + /// The value of the entry. + void Set(string key, string value); + + /// + /// Sets the value of the entry with specified . If an entry with + /// already exists, it will be overwritten. + /// + /// The key of the entry. + /// The value of the entry. + void Set(string key, object value); + + /// + /// Removes the entry with the specified . + /// + /// The key of the entry. + void Remove(string key); + + /// + /// Gets whether the value with the specified key is an instance of . + /// + /// The key. + /// true if the item with the specified is an instance of + /// , otherwise false. + bool IsFile(string key); + + /// + /// Writes the multipart POST data to the specified stream. + /// + /// The stream. + /// The multipart boundary. + void WriteMultipartFormData(Stream stream, string boundary); + + #endregion } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/Collections/IHttpQueryString.cs b/src/Skybrud.Essentials.Http/Collections/IHttpQueryString.cs index 8bd4f60..51ee8e5 100644 --- a/src/Skybrud.Essentials.Http/Collections/IHttpQueryString.cs +++ b/src/Skybrud.Essentials.Http/Collections/IHttpQueryString.cs @@ -1,137 +1,135 @@ using System.Collections.Generic; -namespace Skybrud.Essentials.Http.Collections { - - /// - /// Interface describing a collection of items representing a query string. Depending on the implementation, the - /// collection may support multiple items sharing the same key. - /// - public interface IHttpQueryString : IEnumerable> { - - #region Properties - - /// - /// Gets the amount of items stored in the query string. - /// - int Count { get; } - - /// - /// Gets whether the query string is empty. - /// - bool IsEmpty { get; } - - /// - /// Gets an array of the keys of all items in the query string. - /// - string[] Keys { get; } - - /// - /// Gets an array of all items in the query string. - /// - KeyValuePair[] Items { get; } - - /// - /// Gets the value of the first item with the specified . - /// - /// The key of the item to match. - /// The value of the item, or null if not found. - string? this[string key] { get; } - - /// - /// Gets whether this implementation of supports duplicate keys. - /// - bool SupportsDuplicateKeys { get; } - - #endregion - - #region Member methods - - /// - /// Adds an item with the specified and . - /// - /// The key of the item. - /// The value of the item. - void Add(string key, object value); - - /// - /// Sets the of an entry with the specified . If one or more entries with - /// already exist, these will be overwritten. - /// - /// The key of the entry. - /// The value of the entry. - void Set(string key, object value); - - /// - /// Removes the value with the specified . - /// - /// The key of the element to remove. - /// true if the element is successfully found and removed; otherwise, false. This method returns false if is not found. - bool Remove(string key); - - /// - /// Creates a copy of the . - /// - /// A copy of the . - IHttpQueryString Clone(); - - /// - /// Gets a string representation of the query string. - /// - /// The query string as an URL encoded string. - string ToString(); - - /// - /// Return whether the query string contains an entry with the specified . - /// - /// The key of the entry. - /// true if the query string contains the specified , otherwise - /// false. - bool ContainsKey(string key); - - /// - /// Gets the value of the entry with the specified . - /// - /// The key of the entry. - /// The value of the entry, or null if not found. - string? GetString(string key); - - /// - /// Gets the value of the entry with the specified . - /// - /// The key of the entry. - /// The value of the entry, or 0 if not found. - int GetInt32(string key); - - /// - /// Gets the value of the entry with the specified . - /// - /// The key of the entry. - /// The value of the entry, or 0 if not found. - long GetInt64(string key); - - /// - /// Gets the value of the entry with the specified . - /// - /// The key of the entry. - /// The value of the entry, or 0 if not found. - bool GetBoolean(string key); - - /// - /// Gets the value of the entry with the specified . - /// - /// The key of the entry. - /// The value of the entry, or 0 if not found. - double GetDouble(string key); - - /// - /// Gets the value of the entry with the specified . - /// - /// The key of the entry. - /// The value of the entry, or 0 if not found. - float GetFloat(string key); - - #endregion - - } +namespace Skybrud.Essentials.Http.Collections; + +/// +/// Interface describing a collection of items representing a query string. Depending on the implementation, the +/// collection may support multiple items sharing the same key. +/// +public interface IHttpQueryString : IEnumerable> { + + #region Properties + + /// + /// Gets the amount of items stored in the query string. + /// + int Count { get; } + + /// + /// Gets whether the query string is empty. + /// + bool IsEmpty { get; } + + /// + /// Gets an array of the keys of all items in the query string. + /// + string[] Keys { get; } + + /// + /// Gets an array of all items in the query string. + /// + KeyValuePair[] Items { get; } + + /// + /// Gets the value of the first item with the specified . + /// + /// The key of the item to match. + /// The value of the item, or null if not found. + string? this[string key] { get; } + + /// + /// Gets whether this implementation of supports duplicate keys. + /// + bool SupportsDuplicateKeys { get; } + + #endregion + + #region Member methods + + /// + /// Adds an item with the specified and . + /// + /// The key of the item. + /// The value of the item. + void Add(string key, object value); + + /// + /// Sets the of an entry with the specified . If one or more entries with + /// already exist, these will be overwritten. + /// + /// The key of the entry. + /// The value of the entry. + void Set(string key, object value); + + /// + /// Removes the value with the specified . + /// + /// The key of the element to remove. + /// true if the element is successfully found and removed; otherwise, false. This method returns false if is not found. + bool Remove(string key); + + /// + /// Creates a copy of the . + /// + /// A copy of the . + IHttpQueryString Clone(); + + /// + /// Gets a string representation of the query string. + /// + /// The query string as an URL encoded string. + string ToString(); + + /// + /// Return whether the query string contains an entry with the specified . + /// + /// The key of the entry. + /// true if the query string contains the specified , otherwise + /// false. + bool ContainsKey(string key); + + /// + /// Gets the value of the entry with the specified . + /// + /// The key of the entry. + /// The value of the entry, or null if not found. + string? GetString(string key); + + /// + /// Gets the value of the entry with the specified . + /// + /// The key of the entry. + /// The value of the entry, or 0 if not found. + int GetInt32(string key); + + /// + /// Gets the value of the entry with the specified . + /// + /// The key of the entry. + /// The value of the entry, or 0 if not found. + long GetInt64(string key); + + /// + /// Gets the value of the entry with the specified . + /// + /// The key of the entry. + /// The value of the entry, or 0 if not found. + bool GetBoolean(string key); + + /// + /// Gets the value of the entry with the specified . + /// + /// The key of the entry. + /// The value of the entry, or 0 if not found. + double GetDouble(string key); + + /// + /// Gets the value of the entry with the specified . + /// + /// The key of the entry. + /// The value of the entry, or 0 if not found. + float GetFloat(string key); + + #endregion } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/Exceptions/HttpException.cs b/src/Skybrud.Essentials.Http/Exceptions/HttpException.cs index d53be3f..c9380a8 100644 --- a/src/Skybrud.Essentials.Http/Exceptions/HttpException.cs +++ b/src/Skybrud.Essentials.Http/Exceptions/HttpException.cs @@ -1,39 +1,37 @@ using System; using System.Net; -namespace Skybrud.Essentials.Http.Exceptions { +namespace Skybrud.Essentials.Http.Exceptions; - /// - /// Class representing a basic HTTP exception. - /// - public class HttpException : Exception, IHttpException { - - #region Properties +/// +/// Class representing a basic HTTP exception. +/// +public class HttpException : Exception, IHttpException { - /// - /// Gets a reference to the underlying . - /// - public IHttpResponse Response { get; } + #region Properties - /// - /// Gets the HTTP status code returned by the Toggl API. - /// - public HttpStatusCode StatusCode => Response.StatusCode; - - #endregion + /// + /// Gets a reference to the underlying . + /// + public IHttpResponse Response { get; } - #region Constructors + /// + /// Gets the HTTP status code returned by the Toggl API. + /// + public HttpStatusCode StatusCode => Response.StatusCode; - /// - /// Initializes a new exception based on the specified . - /// - /// The instance of representing the raw response. - public HttpException(IHttpResponse response) : base($"Invalid response received (status: {(int) response.StatusCode})") { - Response = response; - } + #endregion - #endregion + #region Constructors + /// + /// Initializes a new exception based on the specified . + /// + /// The instance of representing the raw response. + public HttpException(IHttpResponse response) : base($"Invalid response received (status: {(int) response.StatusCode})") { + Response = response; } + #endregion + } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/Exceptions/IHttpException.cs b/src/Skybrud.Essentials.Http/Exceptions/IHttpException.cs index ffda565..a97caf2 100644 --- a/src/Skybrud.Essentials.Http/Exceptions/IHttpException.cs +++ b/src/Skybrud.Essentials.Http/Exceptions/IHttpException.cs @@ -1,22 +1,20 @@ using System.Net; -namespace Skybrud.Essentials.Http.Exceptions { +namespace Skybrud.Essentials.Http.Exceptions; + +/// +/// Interface representing an error response as the result of a HTTP request. +/// +public interface IHttpException { /// - /// Interface representing an error response as the result of a HTTP request. + /// Gets a reference to the underlying . /// - public interface IHttpException { - - /// - /// Gets a reference to the underlying . - /// - IHttpResponse Response { get; } - - /// - /// Gets the HTTP status code of the response. - /// - HttpStatusCode StatusCode { get; } + IHttpResponse Response { get; } - } + /// + /// Gets the HTTP status code of the response. + /// + HttpStatusCode StatusCode { get; } } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/HttpConstants.cs b/src/Skybrud.Essentials.Http/HttpConstants.cs index 86a8b6d..d7b6729 100644 --- a/src/Skybrud.Essentials.Http/HttpConstants.cs +++ b/src/Skybrud.Essentials.Http/HttpConstants.cs @@ -1,45 +1,43 @@ -namespace Skybrud.Essentials.Http { - +namespace Skybrud.Essentials.Http; + +/// +/// Static class with various HTTP related constants. +/// +public static class HttpConstants { + + /// + /// Constants for the application/x-www-form-urlencoded content type. + /// + public const string ApplicationFormEncoded = "application/x-www-form-urlencoded"; + + /// + /// Constants for the application/json content type. + /// + public const string ApplicationJson = "application/json"; + + /// + /// Constants for the application/atom+xml content type. + /// + public const string ApplicationAtom = "application/atom+xml"; + /// - /// Static class with various HTTP related constants. + /// Constants for the application/rss+xml content type. /// - public static class HttpConstants { - - /// - /// Constants for the application/x-www-form-urlencoded content type. - /// - public const string ApplicationFormEncoded = "application/x-www-form-urlencoded"; - - /// - /// Constants for the application/json content type. - /// - public const string ApplicationJson = "application/json"; - - /// - /// Constants for the application/atom+xml content type. - /// - public const string ApplicationAtom = "application/atom+xml"; - - /// - /// Constants for the application/rss+xml content type. - /// - public const string ApplicationRss = "application/rss+xml"; - - /// - /// Constants for the text/plain content type. - /// - public const string TextPlain = "text/plain"; - - /// - /// Constants for the text/html content type. - /// - public const string TextHtml = "text/html"; - - /// - /// Constants for the text/xml content type. - /// - public const string TextXml = "text/xml"; - - } - -} + public const string ApplicationRss = "application/rss+xml"; + + /// + /// Constants for the text/plain content type. + /// + public const string TextPlain = "text/plain"; + + /// + /// Constants for the text/html content type. + /// + public const string TextHtml = "text/html"; + + /// + /// Constants for the text/xml content type. + /// + public const string TextXml = "text/xml"; + +} \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/HttpMethod.cs b/src/Skybrud.Essentials.Http/HttpMethod.cs index 6a29b71..6f87eff 100644 --- a/src/Skybrud.Essentials.Http/HttpMethod.cs +++ b/src/Skybrud.Essentials.Http/HttpMethod.cs @@ -1,40 +1,38 @@ -namespace Skybrud.Essentials.Http { +namespace Skybrud.Essentials.Http; + +/// +/// Enum class representing the HTTP method to be used for a HTTP request. +/// +public enum HttpMethod { + + /// + /// Indicates a request should be made using the GET HTTP method. + /// + Get, + + /// + /// Indicates a request should be made using the HEAD HTTP method. + /// + Head, + + /// + /// Indicates a request should be made using the POST HTTP method. + /// + Post, + + /// + /// Indicates a request should be made using the PUT HTTP method. + /// + Put, + + /// + /// Indicates a request should be made using the PATCH HTTP method. + /// + Patch, /// - /// Enum class representing the HTTP method to be used for a HTTP request. + /// Indicates a request should be made using the DELETE HTTP method. /// - public enum HttpMethod { - - /// - /// Indicates a request should be made using the GET HTTP method. - /// - Get, - - /// - /// Indicates a request should be made using the HEAD HTTP method. - /// - Head, - - /// - /// Indicates a request should be made using the POST HTTP method. - /// - Post, - - /// - /// Indicates a request should be made using the PUT HTTP method. - /// - Put, - - /// - /// Indicates a request should be made using the PATCH HTTP method. - /// - Patch, - - /// - /// Indicates a request should be made using the DELETE HTTP method. - /// - Delete - - } + Delete } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/HttpPostFileValue.cs b/src/Skybrud.Essentials.Http/HttpPostFileValue.cs index 6703147..904be0a 100644 --- a/src/Skybrud.Essentials.Http/HttpPostFileValue.cs +++ b/src/Skybrud.Essentials.Http/HttpPostFileValue.cs @@ -1,117 +1,115 @@ using System.IO; using Skybrud.Essentials.Http.Collections; -namespace Skybrud.Essentials.Http { +namespace Skybrud.Essentials.Http; + +/// +/// Class representing a HTTP POST value based on a local file. +/// +public class HttpPostFileValue : IHttpPostValue { + + #region Properties /// - /// Class representing a HTTP POST value based on a local file. + /// Gets the name/key of the value. /// - public class HttpPostFileValue : IHttpPostValue { - - #region Properties - - /// - /// Gets the name/key of the value. - /// - public string Name { get; } - - /// - /// Gets the content type of the file. - /// - public string? ContentType { get; } - - /// - /// Gets the name of the file. - /// - public string? FileName { get; } - - /// - /// Gets the data of the file. - /// - public byte[] Data { get; } - - #endregion - - #region Constructors - - /// - /// Initializea a new instance from the specified and . - /// - /// The name of the value. - /// The path to the file. - public HttpPostFileValue(string name, string path) : this(name, path, null, null) { } - - /// - /// Initializes a new instance from the specified , , - /// and . - /// - /// The name of the value. - /// The path to the file. - /// The content type of the file. - /// The name of the file. - public HttpPostFileValue(string name, string path, string? contentType, string? filename) { - - Name = name; - Data = File.ReadAllBytes(path); - ContentType = contentType; - FileName = filename ?? Path.GetFileName(path); - - if (ContentType != null) return; - - switch (Path.GetExtension(path).ToLower()) { - case ".jpg": - case ".jpeg": - ContentType = "image/jpeg"; - break; - case ".png": - ContentType = "image/png"; - break; - case ".gif": - ContentType = "image/gif"; - break; - case ".tiff": - ContentType = "image/tiff"; - break; - } - - } + public string Name { get; } - #endregion + /// + /// Gets the content type of the file. + /// + public string? ContentType { get; } - #region Member methods + /// + /// Gets the name of the file. + /// + public string? FileName { get; } - /// - /// Writes the value to the specified . - /// - /// The stream the value should be written to. - /// The multipart boundary. - /// The characters used to indicate a new line. - /// Whether the value is the last in the request body. - public void WriteToMultipartStream(Stream stream, string boundary, string newLine, bool isLast) { + /// + /// Gets the data of the file. + /// + public byte[] Data { get; } - HttpPostData.Write(stream, "--" + boundary + newLine); - HttpPostData.Write(stream, "Content-Disposition: form-data; name=\"" + Name + "\"; filename=\"" + FileName + "\"" + newLine); - HttpPostData.Write(stream, "Content-Type: " + ContentType + newLine); - HttpPostData.Write(stream, newLine); + #endregion - stream.Write(Data, 0, Data.Length); + #region Constructors - HttpPostData.Write(stream, newLine); - HttpPostData.Write(stream, newLine); - HttpPostData.Write(stream, "--" + boundary + (isLast ? "--" : "") + newLine); + /// + /// Initializea a new instance from the specified and . + /// + /// The name of the value. + /// The path to the file. + public HttpPostFileValue(string name, string path) : this(name, path, null, null) { } + /// + /// Initializes a new instance from the specified , , + /// and . + /// + /// The name of the value. + /// The path to the file. + /// The content type of the file. + /// The name of the file. + public HttpPostFileValue(string name, string path, string? contentType, string? filename) { + + Name = name; + Data = File.ReadAllBytes(path); + ContentType = contentType; + FileName = filename ?? Path.GetFileName(path); + + if (ContentType != null) return; + + switch (Path.GetExtension(path).ToLower()) { + case ".jpg": + case ".jpeg": + ContentType = "image/jpeg"; + break; + case ".png": + ContentType = "image/png"; + break; + case ".gif": + ContentType = "image/gif"; + break; + case ".tiff": + ContentType = "image/tiff"; + break; } - /// - /// Gets a string representation of the value. - /// - /// The value as a string. - public override string ToString() { - return FileName ?? Name; - } + } + + #endregion + + #region Member methods + + /// + /// Writes the value to the specified . + /// + /// The stream the value should be written to. + /// The multipart boundary. + /// The characters used to indicate a new line. + /// Whether the value is the last in the request body. + public void WriteToMultipartStream(Stream stream, string boundary, string newLine, bool isLast) { - #endregion + HttpPostData.Write(stream, "--" + boundary + newLine); + HttpPostData.Write(stream, "Content-Disposition: form-data; name=\"" + Name + "\"; filename=\"" + FileName + "\"" + newLine); + HttpPostData.Write(stream, "Content-Type: " + ContentType + newLine); + HttpPostData.Write(stream, newLine); + + stream.Write(Data, 0, Data.Length); + + HttpPostData.Write(stream, newLine); + HttpPostData.Write(stream, newLine); + HttpPostData.Write(stream, "--" + boundary + (isLast ? "--" : "") + newLine); } + /// + /// Gets a string representation of the value. + /// + /// The value as a string. + public override string ToString() { + return FileName ?? Name; + } + + #endregion + } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/HttpPostValue.cs b/src/Skybrud.Essentials.Http/HttpPostValue.cs index 1f1d23e..c65af8b 100644 --- a/src/Skybrud.Essentials.Http/HttpPostValue.cs +++ b/src/Skybrud.Essentials.Http/HttpPostValue.cs @@ -1,69 +1,67 @@ using System.IO; using Skybrud.Essentials.Http.Collections; -namespace Skybrud.Essentials.Http { +namespace Skybrud.Essentials.Http; - /// - /// Class representing a string HTTP POST value. - /// - public class HttpPostValue : IHttpPostValue { +/// +/// Class representing a string HTTP POST value. +/// +public class HttpPostValue : IHttpPostValue { - #region Properties + #region Properties - /// - /// Gets the name/key of the value. - /// - public string Name { get; } - - /// - /// Gets or sets the value. - /// - public string Value { get; set; } + /// + /// Gets the name/key of the value. + /// + public string Name { get; } - #endregion + /// + /// Gets or sets the value. + /// + public string Value { get; set; } - #region Constructors + #endregion - /// - /// Initializes a new HTTP POST value from the specified and . - /// - /// The name/key of the value. - /// The value. - public HttpPostValue(string name, string value) { - Name = name; - Value = value; - } + #region Constructors - #endregion + /// + /// Initializes a new HTTP POST value from the specified and . + /// + /// The name/key of the value. + /// The value. + public HttpPostValue(string name, string value) { + Name = name; + Value = value; + } - /// - /// Writes the value to the specified . - /// - /// The stream the value should be written to. - /// The multipart boundary. - /// The characters used to indicate a new line. - /// Whether the value is the last in the request body. - public void WriteToMultipartStream(Stream stream, string boundary, string newLine, bool isLast) { + #endregion - HttpPostData.Write(stream, "--" + boundary + newLine); - HttpPostData.Write(stream, "Content-Disposition: form-data; name=\"" + Name + "\"" + newLine); - HttpPostData.Write(stream, newLine); + /// + /// Writes the value to the specified . + /// + /// The stream the value should be written to. + /// The multipart boundary. + /// The characters used to indicate a new line. + /// Whether the value is the last in the request body. + public void WriteToMultipartStream(Stream stream, string boundary, string newLine, bool isLast) { - HttpPostData.Write(stream, Value); + HttpPostData.Write(stream, "--" + boundary + newLine); + HttpPostData.Write(stream, "Content-Disposition: form-data; name=\"" + Name + "\"" + newLine); + HttpPostData.Write(stream, newLine); - HttpPostData.Write(stream, newLine); - HttpPostData.Write(stream, "--" + boundary + (isLast ? "--" : "") + newLine); + HttpPostData.Write(stream, Value); - } + HttpPostData.Write(stream, newLine); + HttpPostData.Write(stream, "--" + boundary + (isLast ? "--" : "") + newLine); - /// - /// Gets a string representation of the value. - /// - /// The value as a string. - public override string ToString() { - return Value; - } + } + /// + /// Gets a string representation of the value. + /// + /// The value as a string. + public override string ToString() { + return Value; } } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/HttpRequest.Async.cs b/src/Skybrud.Essentials.Http/HttpRequest.Async.cs index 8c20dc5..c279776 100644 --- a/src/Skybrud.Essentials.Http/HttpRequest.Async.cs +++ b/src/Skybrud.Essentials.Http/HttpRequest.Async.cs @@ -10,46 +10,46 @@ // ReSharper disable UseAwaitUsing // ReSharper disable ConvertToUsingDeclaration -namespace Skybrud.Essentials.Http { +namespace Skybrud.Essentials.Http; - public partial class HttpRequest { +public partial class HttpRequest { - /// - /// Executes the request and returns the corresponding response as an instance of . - /// - /// An instance of representing the response. - public virtual async Task GetResponseAsync() { - return await GetResponseAsync(null); - } + /// + /// Executes the request and returns the corresponding response as an instance of . + /// + /// An instance of representing the response. + public virtual async Task GetResponseAsync() { + return await GetResponseAsync(null); + } - /// - /// Executes the request and returns the corresponding response as an instance of . - /// - /// Lets you specify a callback method for modifying the underlying . - /// An instance of representing the response. - public virtual async Task GetResponseAsync(Action? callback) { + /// + /// Executes the request and returns the corresponding response as an instance of . + /// + /// Lets you specify a callback method for modifying the underlying . + /// An instance of representing the response. + public virtual async Task GetResponseAsync(Action? callback) { - // Build the URL - string url = Url; - if (!QueryString.IsEmpty) url += (url.Contains("?") ? "&" : "?") + QueryString; + // Build the URL + string url = Url; + if (!QueryString.IsEmpty) url += (url.Contains("?") ? "&" : "?") + QueryString; - // Initialize the request - HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url); + // Initialize the request + HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url); - // Misc - request.Method = Method.ToUpper(); - request.Credentials = Credentials; - request.Headers = Headers.Headers; - request.Accept = Accept; - request.CookieContainer = Cookies.Container; - if (string.IsNullOrWhiteSpace(ContentType) == false) request.ContentType = ContentType; + // Misc + request.Method = Method.ToUpper(); + request.Credentials = Credentials; + request.Headers = Headers.Headers; + request.Accept = Accept; + request.CookieContainer = Cookies.Container; + if (string.IsNullOrWhiteSpace(ContentType) == false) request.ContentType = ContentType; #if NET_STANDARD2 - request.AutomaticDecompression = AutomaticDecompression; - request.MediaType = MediaType; - request.TransferEncoding = TransferEncoding; - request.Connection = Connection; - request.Expect = Expect; + request.AutomaticDecompression = AutomaticDecompression; + request.MediaType = MediaType; + request.TransferEncoding = TransferEncoding; + request.Connection = Connection; + request.Expect = Expect; #endif #if NET_FRAMEWORK @@ -58,95 +58,93 @@ public virtual async Task GetResponseAsync(Action if (string.IsNullOrWhiteSpace(UserAgent) == false) request.UserAgent = UserAgent; if (string.IsNullOrWhiteSpace(Referer) == false) request.Referer = Referer; #else - if (string.IsNullOrWhiteSpace(Host) == false) request.Headers["Host"] = Host; - if (string.IsNullOrWhiteSpace(UserAgent) == false) request.Headers["User-Agent"] = UserAgent; - if (string.IsNullOrWhiteSpace(Referer) == false) request.Headers["Referer"] = Referer; + if (string.IsNullOrWhiteSpace(Host) == false) request.Headers["Host"] = Host; + if (string.IsNullOrWhiteSpace(UserAgent) == false) request.Headers["User-Agent"] = UserAgent; + if (string.IsNullOrWhiteSpace(Referer) == false) request.Headers["Referer"] = Referer; #endif - // Handle various POST scenarios - if (string.IsNullOrWhiteSpace(Body) == false) { + // Handle various POST scenarios + if (string.IsNullOrWhiteSpace(Body) == false) { - // Get the bytes for the request body - byte[] bytes = Encoding.UTF8.GetBytes(Body!); + // Get the bytes for the request body + byte[] bytes = Encoding.UTF8.GetBytes(Body!); - // Set the length of the request body - SetRequestContentLength(request, bytes.Length); - - // Write the body to the request stream - Task hest = request.GetRequestStreamAsync(); - using (Stream stream = hest.Result) { - await stream.WriteAsync(bytes, 0, bytes.Length); - } + // Set the length of the request body + SetRequestContentLength(request, bytes.Length); - } else if (BinaryBody != null) { + // Write the body to the request stream + Task hest = request.GetRequestStreamAsync(); + using (Stream stream = hest.Result) { + await stream.WriteAsync(bytes, 0, bytes.Length); + } - // Set the length of the request body - SetRequestContentLength(request, BinaryBody.Length); + } else if (BinaryBody != null) { - // Write the body to the request stream - using (Stream stream = request.GetRequestStreamAsync().Result) { - await stream.WriteAsync(BinaryBody, 0, BinaryBody.Length); - } + // Set the length of the request body + SetRequestContentLength(request, BinaryBody.Length); - } else if (Method is HttpMethod.Post or HttpMethod.Put or HttpMethod.Patch or HttpMethod.Delete) { + // Write the body to the request stream + using (Stream stream = request.GetRequestStreamAsync().Result) { + await stream.WriteAsync(BinaryBody, 0, BinaryBody.Length); + } - if (PostData.IsMultipart) { + } else if (Method is HttpMethod.Post or HttpMethod.Put or HttpMethod.Patch or HttpMethod.Delete) { - // Declare the boundary to be used for the multipart data - string boundary = Guid.NewGuid().ToString().Replace("-", ""); + if (PostData.IsMultipart) { - // Set the content type (including the boundary) - request.ContentType = "multipart/form-data; boundary=" + boundary; + // Declare the boundary to be used for the multipart data + string boundary = Guid.NewGuid().ToString().Replace("-", ""); - // Write the multipart body to the request stream - Task hest = request.GetRequestStreamAsync(); - hest.Wait(); - using (Stream stream = hest.Result) { - PostData.WriteMultipartFormData(stream, boundary); - } + // Set the content type (including the boundary) + request.ContentType = "multipart/form-data; boundary=" + boundary; - } else { + // Write the multipart body to the request stream + Task hest = request.GetRequestStreamAsync(); + hest.Wait(); + using (Stream stream = hest.Result) { + PostData.WriteMultipartFormData(stream, boundary); + } - // Convert the POST data to an URL encoded string - string dataString = PostData.ToString() ?? string.Empty; + } else { - // Get the bytes for the request body - byte[] bytes = Encoding.UTF8.GetBytes(dataString); + // Convert the POST data to an URL encoded string + string dataString = PostData.ToString() ?? string.Empty; - // Set the content type - request.ContentType ??= HttpConstants.ApplicationFormEncoded; + // Get the bytes for the request body + byte[] bytes = Encoding.UTF8.GetBytes(dataString); - // Set the length of the request body - SetRequestContentLength(request, bytes.Length); + // Set the content type + request.ContentType ??= HttpConstants.ApplicationFormEncoded; - // Write the body to the request stream - Task hest = request.GetRequestStreamAsync(); - hest.Wait(); - using (Stream stream = hest.Result) { - await stream.WriteAsync(bytes, 0, bytes.Length); - } + // Set the length of the request body + SetRequestContentLength(request, bytes.Length); + // Write the body to the request stream + Task hest = request.GetRequestStreamAsync(); + hest.Wait(); + using (Stream stream = hest.Result) { + await stream.WriteAsync(bytes, 0, bytes.Length); } } - // Call the callback - callback?.Invoke(request); + } - // Get the response - try { + // Call the callback + callback?.Invoke(request); - WebResponse response = await request.GetResponseAsync(); + // Get the response + try { - return HttpResponse.GetFromWebResponse((HttpWebResponse) response, this); + WebResponse response = await request.GetResponseAsync(); - } catch (WebException ex) { + return HttpResponse.GetFromWebResponse((HttpWebResponse) response, this); - if (ex.Status != WebExceptionStatus.ProtocolError) throw; + } catch (WebException ex) { - return HttpResponse.GetFromWebResponse((HttpWebResponse) ex.Response!, this); + if (ex.Status != WebExceptionStatus.ProtocolError) throw; - } + return HttpResponse.GetFromWebResponse((HttpWebResponse) ex.Response!, this); } diff --git a/src/Skybrud.Essentials.Http/HttpRequest.cs b/src/Skybrud.Essentials.Http/HttpRequest.cs index d145fcf..398df71 100644 --- a/src/Skybrud.Essentials.Http/HttpRequest.cs +++ b/src/Skybrud.Essentials.Http/HttpRequest.cs @@ -17,50 +17,50 @@ // ReSharper disable ConditionalAccessQualifierIsNonNullableAccordingToAPIContract // ReSharper disable once RedundantSuppressNullableWarningExpression -namespace Skybrud.Essentials.Http { +namespace Skybrud.Essentials.Http; - /// - /// Wrapper class for . - /// - public partial class HttpRequest : IHttpRequest { +/// +/// Wrapper class for . +/// +public partial class HttpRequest : IHttpRequest { - #region Private fields + #region Private fields - private IHttpHeaderCollection _headers = new HttpHeaderCollection(); - private IHttpQueryString _queryString = new HttpQueryString(); - private IHttpPostData _postData = new HttpPostData(); - private IHttpCookieCollection _cookies = new HttpCookieCollection(); + private IHttpHeaderCollection _headers = new HttpHeaderCollection(); + private IHttpQueryString _queryString = new HttpQueryString(); + private IHttpPostData _postData = new HttpPostData(); + private IHttpCookieCollection _cookies = new HttpCookieCollection(); - #endregion + #endregion - #region Properties + #region Properties - /// - /// Gets or sets the HTTP method of the request. - /// - public HttpMethod Method { get; set; } + /// + /// Gets or sets the HTTP method of the request. + /// + public HttpMethod Method { get; set; } - /// - /// Gets or sets the credentials (username and password) of the request. - /// - public ICredentials? Credentials { get; set; } + /// + /// Gets or sets the credentials (username and password) of the request. + /// + public ICredentials? Credentials { get; set; } - /// - /// Gets or sets the URL of the request. The query string can either be specified directly in the URL, or - /// separately through the property. - /// - public string Url { get; set; } + /// + /// Gets or sets the URL of the request. The query string can either be specified directly in the URL, or + /// separately through the property. + /// + public string Url { get; set; } - /// - /// Gets or sets the HTTP host of the request. If left blank, the host will be based on - /// instead. - /// - public string? Host { get; set; } + /// + /// Gets or sets the HTTP host of the request. If left blank, the host will be based on + /// instead. + /// + public string? Host { get; set; } - /// - /// Gets or sets the encoding of the request. Default is UTF-8. - /// - public Encoding Encoding { get; set; } + /// + /// Gets or sets the encoding of the request. Default is UTF-8. + /// + public Encoding Encoding { get; set; } #if NET_FRAMEWORK @@ -71,122 +71,122 @@ public partial class HttpRequest : IHttpRequest { #endif - /// - /// Gets or sets the collection of headers. - /// - public IHttpHeaderCollection Headers { - get => _headers; - set => _headers = value ?? new HttpHeaderCollection(); - } + /// + /// Gets or sets the collection of headers. + /// + public IHttpHeaderCollection Headers { + get => _headers; + set => _headers = value ?? new HttpHeaderCollection(); + } - /// - /// Gets or sets the query string of the request. - /// - public IHttpQueryString QueryString { - get => _queryString; - set => _queryString = value ?? new HttpQueryString(); - } + /// + /// Gets or sets the query string of the request. + /// + public IHttpQueryString QueryString { + get => _queryString; + set => _queryString = value ?? new HttpQueryString(); + } - /// - /// Gets or sets the POST data of the request. - /// - public IHttpPostData PostData { - get => _postData; - set => _postData = value ?? new HttpPostData(); - } + /// + /// Gets or sets the POST data of the request. + /// + public IHttpPostData PostData { + get => _postData; + set => _postData = value ?? new HttpPostData(); + } - /// - /// Gets or sets the to be used for the request. - /// - public IHttpCookieCollection Cookies { - get => _cookies; - set => _cookies = value ?? new HttpCookieCollection(); - } + /// + /// Gets or sets the to be used for the request. + /// + public IHttpCookieCollection Cookies { + get => _cookies; + set => _cookies = value ?? new HttpCookieCollection(); + } - /// - /// Gets or sets the content type of the request. - /// - public string? ContentType { get; set; } + /// + /// Gets or sets the content type of the request. + /// + public string? ContentType { get; set; } - /// - /// Gets or sets the body of the request. - /// - public string? Body { get; set; } + /// + /// Gets or sets the body of the request. + /// + public string? Body { get; set; } - /// - /// Gets or sets the binary body of the request. - /// - public byte[]? BinaryBody { get; set; } + /// + /// Gets or sets the binary body of the request. + /// + public byte[]? BinaryBody { get; set; } - #region HTTP Headers + #region HTTP Headers - /// - /// Gets a or sets a list of content types that are acceptable for the response - eg. text/html, - /// text/html,application/xhtml+xml or application/json. This property corresponds to the - /// Accept HTTP header. - /// - /// - /// https://en.wikipedia.org/wiki/Content_negotiation - /// - public string? Accept { get; set; } + /// + /// Gets a or sets a list of content types that are acceptable for the response - eg. text/html, + /// text/html,application/xhtml+xml or application/json. This property corresponds to the + /// Accept HTTP header. + /// + /// + /// https://en.wikipedia.org/wiki/Content_negotiation + /// + public string? Accept { get; set; } - /// - /// Gets or sets the character sets that are acceptable - eg. utf8. This property corresponds to - /// the Accept-Charset HTTP header. - /// - public string? AcceptCharset { - get => Headers.AcceptCharset; - set => Headers.AcceptCharset = value; - } + /// + /// Gets or sets the character sets that are acceptable - eg. utf8. This property corresponds to + /// the Accept-Charset HTTP header. + /// + public string? AcceptCharset { + get => Headers.AcceptCharset; + set => Headers.AcceptCharset = value; + } - /// - /// Gets or sets the a list of acceptable encodings - eg. gzip or gzip, deflate. This - /// property corresponds to the Accept-Encoding HTTP header. - /// - /// - /// https://en.wikipedia.org/wiki/HTTP_compression - /// - public string? AcceptEncoding { - get => Headers.AcceptEncoding; - set => Headers.AcceptEncoding = value; - } + /// + /// Gets or sets the a list of acceptable encodings - eg. gzip or gzip, deflate. This + /// property corresponds to the Accept-Encoding HTTP header. + /// + /// + /// https://en.wikipedia.org/wiki/HTTP_compression + /// + public string? AcceptEncoding { + get => Headers.AcceptEncoding; + set => Headers.AcceptEncoding = value; + } - /// - /// Gets or sets the accept language header of the request - eg. en-US, en or da. This - /// property corresponds to the Accept-Language HTTP header. - /// - /// - /// https://en.wikipedia.org/wiki/Content_negotiation - /// - public string? AcceptLanguage { - get => Headers.AcceptLanguage; - set => Headers.AcceptLanguage = value; - } + /// + /// Gets or sets the accept language header of the request - eg. en-US, en or da. This + /// property corresponds to the Accept-Language HTTP header. + /// + /// + /// https://en.wikipedia.org/wiki/Content_negotiation + /// + public string? AcceptLanguage { + get => Headers.AcceptLanguage; + set => Headers.AcceptLanguage = value; + } - /// - /// Gets or sets the authentication credentials for HTTP authentication. This property corresponds to the - /// Authorization HTTP header. - /// - public string? Authorization { - get => Headers.Authorization; - set => Headers.Authorization = value; - } + /// + /// Gets or sets the authentication credentials for HTTP authentication. This property corresponds to the + /// Authorization HTTP header. + /// + public string? Authorization { + get => Headers.Authorization; + set => Headers.Authorization = value; + } - /// - /// Gets or sets the address of the previous web page from which a link to the currently requested page was - /// followed. (The word "referrer" has been misspelled in the RFC as well as in most implementations to the - /// point that it has become standard usage and is considered correct terminology). This property corresponds - /// to the Referer HTTP header. - /// - public string? Referer { get; set; } + /// + /// Gets or sets the address of the previous web page from which a link to the currently requested page was + /// followed. (The word "referrer" has been misspelled in the RFC as well as in most implementations to the + /// point that it has become standard usage and is considered correct terminology). This property corresponds + /// to the Referer HTTP header. + /// + public string? Referer { get; set; } - /// - /// Gets or sets a string representing the user agent. This property corresponds to the User-Agent - /// HTTP header. - /// - public string? UserAgent { get; set; } + /// + /// Gets or sets a string representing the user agent. This property corresponds to the User-Agent + /// HTTP header. + /// + public string? UserAgent { get; set; } - #endregion + #endregion #if NET_FRAMEWORK_OR_NET_STANDARD_2 || NET5_0_OR_GREATER @@ -217,170 +217,170 @@ public string? Authorization { #endif - #endregion + #endregion - #region Constructors + #region Constructors - /// - /// Initializes a new request with default options. - /// - public HttpRequest() { - Method = HttpMethod.Get; - Encoding = Encoding.UTF8; - Url = string.Empty; + /// + /// Initializes a new request with default options. + /// + public HttpRequest() { + Method = HttpMethod.Get; + Encoding = Encoding.UTF8; + Url = string.Empty; #if NET_FRAMEWORK Timeout = TimeSpan.FromSeconds(100); #endif - } + } - /// - /// Initializes a new request based on the specified and . - /// - /// The HTTP method for the request - eg. or . - /// The URL of the request. The query string may be part of the specified URL or via the property. - public HttpRequest(HttpMethod method, string url) : this() { - Method = method; - Url = url; - } + /// + /// Initializes a new request based on the specified and . + /// + /// The HTTP method for the request - eg. or . + /// The URL of the request. The query string may be part of the specified URL or via the property. + public HttpRequest(HttpMethod method, string url) : this() { + Method = method; + Url = url; + } - /// - /// Initializes a new request based on the specified , and . - /// - /// The HTTP method for the request - eg. or . - /// The URL of the request. - /// The query string of the request. - public HttpRequest(HttpMethod method, string url, IHttpQueryString? queryString) : this() { - Method = method; - Url = url; - QueryString = queryString!; - } + /// + /// Initializes a new request based on the specified , and . + /// + /// The HTTP method for the request - eg. or . + /// The URL of the request. + /// The query string of the request. + public HttpRequest(HttpMethod method, string url, IHttpQueryString? queryString) : this() { + Method = method; + Url = url; + QueryString = queryString!; + } - /// - /// Initializes a new request on the specified , and . - /// - /// The HTTP method for the request - eg. or . - /// The URL of the request. - /// The HTTP POST data of the request. - public HttpRequest(HttpMethod method, string url, IHttpPostData? postData) : this() { - Method = method; - Url = url; - PostData = postData!; - } + /// + /// Initializes a new request on the specified , and . + /// + /// The HTTP method for the request - eg. or . + /// The URL of the request. + /// The HTTP POST data of the request. + public HttpRequest(HttpMethod method, string url, IHttpPostData? postData) : this() { + Method = method; + Url = url; + PostData = postData!; + } - /// - /// Initializes a new request on the specified , , and . - /// - /// The HTTP method for the request - eg. or . - /// The URL of the request. - /// The query string of the request. - /// The HTTP POST data of the request. - public HttpRequest(HttpMethod method, string url, IHttpQueryString? queryString, IHttpPostData? postData) : this() { - Method = method; - Url = url; - QueryString = queryString!; - PostData = postData!; - } + /// + /// Initializes a new request on the specified , , and . + /// + /// The HTTP method for the request - eg. or . + /// The URL of the request. + /// The query string of the request. + /// The HTTP POST data of the request. + public HttpRequest(HttpMethod method, string url, IHttpQueryString? queryString, IHttpPostData? postData) : this() { + Method = method; + Url = url; + QueryString = queryString!; + PostData = postData!; + } - /// - /// Initializes a new request based on the specified , and JSON . - /// - /// With this constructor, the property is automatically set to application/json. - /// - /// The HTTP method for the request - eg. or . - /// The URL of the request. - /// An instance of representing the POST body. - public HttpRequest(HttpMethod method, string url, JToken body) : this() { - Method = method; - Url = url; - ContentType = HttpConstants.ApplicationJson; - Body = body?.ToString(Formatting.None); - } + /// + /// Initializes a new request based on the specified , and JSON . + /// + /// With this constructor, the property is automatically set to application/json. + /// + /// The HTTP method for the request - eg. or . + /// The URL of the request. + /// An instance of representing the POST body. + public HttpRequest(HttpMethod method, string url, JToken body) : this() { + Method = method; + Url = url; + ContentType = HttpConstants.ApplicationJson; + Body = body?.ToString(Formatting.None); + } - /// - /// Initializes a new request based on the specified , and JSON . - /// - /// With this constructor, the property is automatically set to application/json. - /// - /// The HTTP method for the request - eg. or . - /// The URL of the request. - /// An instance of representing the POST body. - /// The formatting to be used when serializing . - public HttpRequest(HttpMethod method, string url, JToken body, Formatting formatting) : this() { - Method = method; - Url = url; - ContentType = HttpConstants.ApplicationJson; - Body = body?.ToString(formatting); - } + /// + /// Initializes a new request based on the specified , and JSON . + /// + /// With this constructor, the property is automatically set to application/json. + /// + /// The HTTP method for the request - eg. or . + /// The URL of the request. + /// An instance of representing the POST body. + /// The formatting to be used when serializing . + public HttpRequest(HttpMethod method, string url, JToken body, Formatting formatting) : this() { + Method = method; + Url = url; + ContentType = HttpConstants.ApplicationJson; + Body = body?.ToString(formatting); + } - /// - /// Initializes a new request based on the specified , , and JSON . - /// - /// With this constructor, the property is automatically set to application/json. - /// - /// The HTTP method for the request - eg. or . - /// The URL of the request. - /// The query string of the request. - /// An instance of representing the POST body. - public HttpRequest(HttpMethod method, string url, IHttpQueryString? queryString, JToken body) : this() { - Method = method; - Url = url; - QueryString = queryString!; - ContentType = HttpConstants.ApplicationJson; - Body = body?.ToString(Formatting.None); - } + /// + /// Initializes a new request based on the specified , , and JSON . + /// + /// With this constructor, the property is automatically set to application/json. + /// + /// The HTTP method for the request - eg. or . + /// The URL of the request. + /// The query string of the request. + /// An instance of representing the POST body. + public HttpRequest(HttpMethod method, string url, IHttpQueryString? queryString, JToken body) : this() { + Method = method; + Url = url; + QueryString = queryString!; + ContentType = HttpConstants.ApplicationJson; + Body = body?.ToString(Formatting.None); + } - /// - /// Initializes a new request based on the specified , , and JSON . - /// - /// With this constructor, the property is automatically set to application/json. - /// - /// The HTTP method for the request - eg. or . - /// The URL of the request. - /// The query string of the request. - /// An instance of representing the POST body. - /// The formatting to be used when serializing . - public HttpRequest(HttpMethod method, string url, IHttpQueryString? queryString, JToken body, Formatting formatting) : this() { - Method = method; - Url = url; - QueryString = queryString!; - ContentType = HttpConstants.ApplicationJson; - Body = body?.ToString(formatting); - } + /// + /// Initializes a new request based on the specified , , and JSON . + /// + /// With this constructor, the property is automatically set to application/json. + /// + /// The HTTP method for the request - eg. or . + /// The URL of the request. + /// The query string of the request. + /// An instance of representing the POST body. + /// The formatting to be used when serializing . + public HttpRequest(HttpMethod method, string url, IHttpQueryString? queryString, JToken body, Formatting formatting) : this() { + Method = method; + Url = url; + QueryString = queryString!; + ContentType = HttpConstants.ApplicationJson; + Body = body?.ToString(formatting); + } - #endregion + #endregion - #region Methods + #region Methods - /// - /// Executes the request and returns the corresponding response as an instance of . - /// - /// An instance of representing the response. - public virtual IHttpResponse GetResponse() { - return GetResponse(null); - } + /// + /// Executes the request and returns the corresponding response as an instance of . + /// + /// An instance of representing the response. + public virtual IHttpResponse GetResponse() { + return GetResponse(null); + } - /// - /// Executes the request and returns the corresponding response as an instance of . - /// - /// Lets you specify a callback method for modifying the underlying . - /// An instance of representing the response. - public virtual IHttpResponse GetResponse(Action? callback) { - - // Build the URL - if (string.IsNullOrWhiteSpace(Url)) throw new PropertyNotSetException(nameof(Url)); - string url = Url; - if (!QueryString.IsEmpty) url += (url.Contains("?") ? "&" : "?") + QueryString; - - // Initialize the request - HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url); - - // Misc - request.Method = Method.ToUpper(); - request.Credentials = Credentials; - request.Headers = Headers.Headers; - request.Accept = Accept; - request.CookieContainer = Cookies.Container; - if (string.IsNullOrWhiteSpace(ContentType) == false) request.ContentType = ContentType; + /// + /// Executes the request and returns the corresponding response as an instance of . + /// + /// Lets you specify a callback method for modifying the underlying . + /// An instance of representing the response. + public virtual IHttpResponse GetResponse(Action? callback) { + + // Build the URL + if (string.IsNullOrWhiteSpace(Url)) throw new PropertyNotSetException(nameof(Url)); + string url = Url; + if (!QueryString.IsEmpty) url += (url.Contains("?") ? "&" : "?") + QueryString; + + // Initialize the request + HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url); + + // Misc + request.Method = Method.ToUpper(); + request.Credentials = Credentials; + request.Headers = Headers.Headers; + request.Accept = Accept; + request.CookieContainer = Cookies.Container; + if (string.IsNullOrWhiteSpace(ContentType) == false) request.ContentType = ContentType; #if NETSTANDARD2_0_OR_GREATER || NET5_0_OR_GREATER request.AutomaticDecompression = AutomaticDecompression; @@ -396,91 +396,91 @@ public virtual IHttpResponse GetResponse(Action? callback) { if (string.IsNullOrWhiteSpace(UserAgent) == false) request.UserAgent = UserAgent; if (string.IsNullOrWhiteSpace(Referer) == false) request.Referer = Referer; #else - if (string.IsNullOrWhiteSpace(Host) == false) request.Headers["Host"] = Host; - if (string.IsNullOrWhiteSpace(UserAgent) == false) request.Headers["User-Agent"] = UserAgent; - if (string.IsNullOrWhiteSpace(Referer) == false) request.Headers["Referer"] = Referer; + if (string.IsNullOrWhiteSpace(Host) == false) request.Headers["Host"] = Host; + if (string.IsNullOrWhiteSpace(UserAgent) == false) request.Headers["User-Agent"] = UserAgent; + if (string.IsNullOrWhiteSpace(Referer) == false) request.Headers["Referer"] = Referer; #endif - // Handle various POST scenarios - if (string.IsNullOrWhiteSpace(Body) == false) { + // Handle various POST scenarios + if (string.IsNullOrWhiteSpace(Body) == false) { - // Get the bytes for the request body - byte[] bytes = Encoding.UTF8.GetBytes(Body!); - - // Set the length of the request body - SetRequestContentLength(request, bytes.Length); + // Get the bytes for the request body + byte[] bytes = Encoding.UTF8.GetBytes(Body!); - // Write the body to the request stream - Task hest = request.GetRequestStreamAsync(); - using (Stream stream = hest.Result) { - stream.Write(bytes, 0, bytes.Length); - } + // Set the length of the request body + SetRequestContentLength(request, bytes.Length); - } else if (BinaryBody != null) { + // Write the body to the request stream + Task hest = request.GetRequestStreamAsync(); + using (Stream stream = hest.Result) { + stream.Write(bytes, 0, bytes.Length); + } - // Set the length of the request body - SetRequestContentLength(request, BinaryBody.Length); + } else if (BinaryBody != null) { - // Write the body to the request stream - using (Stream stream = request.GetRequestStreamAsync().Result) { - stream.Write(BinaryBody, 0, BinaryBody.Length); - } + // Set the length of the request body + SetRequestContentLength(request, BinaryBody.Length); - } else if (Method is HttpMethod.Post or HttpMethod.Put or HttpMethod.Patch or HttpMethod.Delete) { + // Write the body to the request stream + using (Stream stream = request.GetRequestStreamAsync().Result) { + stream.Write(BinaryBody, 0, BinaryBody.Length); + } - if (PostData.IsMultipart) { + } else if (Method is HttpMethod.Post or HttpMethod.Put or HttpMethod.Patch or HttpMethod.Delete) { - // Declare the boundary to be used for the multipart data - string boundary = Guid.NewGuid().ToString().Replace("-", ""); + if (PostData.IsMultipart) { - // Set the content type (including the boundary) - request.ContentType = "multipart/form-data; boundary=" + boundary; + // Declare the boundary to be used for the multipart data + string boundary = Guid.NewGuid().ToString().Replace("-", ""); - // Write the multipart body to the request stream - Task hest = request.GetRequestStreamAsync(); - hest.Wait(); - using (Stream stream = hest.Result) { - PostData.WriteMultipartFormData(stream, boundary); - } + // Set the content type (including the boundary) + request.ContentType = "multipart/form-data; boundary=" + boundary; - } else { + // Write the multipart body to the request stream + Task hest = request.GetRequestStreamAsync(); + hest.Wait(); + using (Stream stream = hest.Result) { + PostData.WriteMultipartFormData(stream, boundary); + } - // Convert the POST data to an URL encoded string - string dataString = PostData.ToString()!; + } else { - // Get the bytes for the request body - byte[] bytes = Encoding.UTF8.GetBytes(dataString); + // Convert the POST data to an URL encoded string + string dataString = PostData.ToString()!; - // Set the content type - request.ContentType ??= HttpConstants.ApplicationFormEncoded; + // Get the bytes for the request body + byte[] bytes = Encoding.UTF8.GetBytes(dataString); - // Set the length of the request body - SetRequestContentLength(request, bytes.Length); + // Set the content type + request.ContentType ??= HttpConstants.ApplicationFormEncoded; - // Write the body to the request stream - Task hest = request.GetRequestStreamAsync(); - hest.Wait(); - using (Stream stream = hest.Result) { - stream.Write(bytes, 0, bytes.Length); - } + // Set the length of the request body + SetRequestContentLength(request, bytes.Length); + // Write the body to the request stream + Task hest = request.GetRequestStreamAsync(); + hest.Wait(); + using (Stream stream = hest.Result) { + stream.Write(bytes, 0, bytes.Length); } } - // Call the callback - callback?.Invoke(request); + } + + // Call the callback + callback?.Invoke(request); - // Get the response - try { + // Get the response + try { #if NETSTANDARD || NET5_0_OR_GREATER - Task responseTask = request.GetResponseAsync(); + Task responseTask = request.GetResponseAsync(); - responseTask.Wait(); + responseTask.Wait(); - return HttpResponse.GetFromWebResponse((HttpWebResponse) responseTask.Result, this); + return HttpResponse.GetFromWebResponse((HttpWebResponse) responseTask.Result, this); #else @@ -488,509 +488,507 @@ public virtual IHttpResponse GetResponse(Action? callback) { #endif - } catch (AggregateException ex) { - - if (ex.InnerException is WebException { Status: WebExceptionStatus.ProtocolError } web) { - return HttpResponse.GetFromWebResponse((HttpWebResponse) web.Response!, this); - } - - throw; + } catch (AggregateException ex) { - } catch (WebException ex) { - if (ex.Status != WebExceptionStatus.ProtocolError) throw; - return HttpResponse.GetFromWebResponse((HttpWebResponse) ex.Response!, this); + if (ex.InnerException is WebException { Status: WebExceptionStatus.ProtocolError } web) { + return HttpResponse.GetFromWebResponse((HttpWebResponse) web.Response!, this); } + throw; + + } catch (WebException ex) { + if (ex.Status != WebExceptionStatus.ProtocolError) throw; + return HttpResponse.GetFromWebResponse((HttpWebResponse) ex.Response!, this); } - private void SetRequestContentLength(HttpWebRequest request, int contentLength) { + } + + private void SetRequestContentLength(HttpWebRequest request, int contentLength) { #if NET_FRAMEWORK request.ContentLength = contentLength; #else - request.Headers["Content-Length"] = contentLength.ToString(); + request.Headers["Content-Length"] = contentLength.ToString(); #endif - } - - #endregion - - #region Static methods + } - /// - /// Initializes a new request with default options. - /// - /// A new instance of . - public static HttpRequest New() { - return new HttpRequest(); - } + #endregion - /// - /// Initializes a new GET request based on the specified . - /// - /// The URL of the request. The query string may be part of the specified URL or via the property. - public static HttpRequest Get(string url) { - return new HttpRequest(HttpMethod.Get, url); - } + #region Static methods - /// - /// Initializes a new GET request based on the specified and . - /// - /// The URL of the request. - /// The query string of the request. - public static HttpRequest Get(string url, IHttpQueryString? queryString) { - return new HttpRequest(HttpMethod.Get, url, queryString); - } + /// + /// Initializes a new request with default options. + /// + /// A new instance of . + public static HttpRequest New() { + return new HttpRequest(); + } - /// - /// Initializes a new POST request based on the specified . - /// - /// The URL of the request. - public static HttpRequest Post(string url) { - return new HttpRequest(HttpMethod.Post, url); - } + /// + /// Initializes a new GET request based on the specified . + /// + /// The URL of the request. The query string may be part of the specified URL or via the property. + public static HttpRequest Get(string url) { + return new HttpRequest(HttpMethod.Get, url); + } - /// - /// Initializes a new POST request based on the specified . - /// - /// The URL of the request. - /// The query string of the request. - public static HttpRequest Post(string url, IHttpQueryString? queryString) { - return new HttpRequest(HttpMethod.Post, url, queryString); - } + /// + /// Initializes a new GET request based on the specified and . + /// + /// The URL of the request. + /// The query string of the request. + public static HttpRequest Get(string url, IHttpQueryString? queryString) { + return new HttpRequest(HttpMethod.Get, url, queryString); + } - /// - /// Initializes a new POST request based on the specified and . - /// - /// The URL of the request. - /// The HTTP POST data of the request. - public static HttpRequest Post(string url, IHttpPostData? postData) { - return new HttpRequest(HttpMethod.Post, url, postData); - } + /// + /// Initializes a new POST request based on the specified . + /// + /// The URL of the request. + public static HttpRequest Post(string url) { + return new HttpRequest(HttpMethod.Post, url); + } - /// - /// Initializes a new POST request based on the specified , and . - /// - /// The URL of the request. - /// The query string of the request. - /// The HTTP POST data of the request. - public static HttpRequest Post(string url, IHttpQueryString? queryString, IHttpPostData? postData) { - return new HttpRequest(HttpMethod.Post, url, queryString, postData); - } + /// + /// Initializes a new POST request based on the specified . + /// + /// The URL of the request. + /// The query string of the request. + public static HttpRequest Post(string url, IHttpQueryString? queryString) { + return new HttpRequest(HttpMethod.Post, url, queryString); + } - /// - /// Initializes a new POST request based on the specified , , and . - /// - /// The URL of the request. - /// The query string of the request. - /// The content type of the request - eg. application/json. - /// The body of the request. - /// An instance of . - public static HttpRequest Post(string url, IHttpQueryString? queryString, string? contentType, string? body) { - return new HttpRequest(HttpMethod.Post, url, queryString).SetContentType(contentType).SetBody(body); - } + /// + /// Initializes a new POST request based on the specified and . + /// + /// The URL of the request. + /// The HTTP POST data of the request. + public static HttpRequest Post(string url, IHttpPostData? postData) { + return new HttpRequest(HttpMethod.Post, url, postData); + } - /// - /// Initializes a new POST request based on the specified and JSON . - /// - /// With this method, the property is automatically set to application/json. - /// - /// The URL of the request. - /// An instance of representing the POST body. - public static HttpRequest Post(string url, JToken body) { - return new HttpRequest(HttpMethod.Post, url, body); - } + /// + /// Initializes a new POST request based on the specified , and . + /// + /// The URL of the request. + /// The query string of the request. + /// The HTTP POST data of the request. + public static HttpRequest Post(string url, IHttpQueryString? queryString, IHttpPostData? postData) { + return new HttpRequest(HttpMethod.Post, url, queryString, postData); + } - /// - /// Initializes a new POST request based on the specified and JSON . - /// - /// With this method, the property is automatically set to application/json. - /// - /// The URL of the request. - /// An instance of representing the POST body. - /// The formatting to be used when serializing . - public static HttpRequest Post(string url, JToken body, Formatting formatting) { - return new HttpRequest(HttpMethod.Post, url, body, formatting); - } + /// + /// Initializes a new POST request based on the specified , , and . + /// + /// The URL of the request. + /// The query string of the request. + /// The content type of the request - eg. application/json. + /// The body of the request. + /// An instance of . + public static HttpRequest Post(string url, IHttpQueryString? queryString, string? contentType, string? body) { + return new HttpRequest(HttpMethod.Post, url, queryString).SetContentType(contentType).SetBody(body); + } - /// - /// Initializes a new POST request based on the specified , and JSON . - /// - /// With this method, the property is automatically set to application/json. - /// - /// The URL of the request. - /// The query string of the request. - /// An instance of representing the POST body. - public static HttpRequest Post(string url, IHttpQueryString? queryString, JToken body) { - return new HttpRequest(HttpMethod.Post, url, queryString, body); - } + /// + /// Initializes a new POST request based on the specified and JSON . + /// + /// With this method, the property is automatically set to application/json. + /// + /// The URL of the request. + /// An instance of representing the POST body. + public static HttpRequest Post(string url, JToken body) { + return new HttpRequest(HttpMethod.Post, url, body); + } - /// - /// Initializes a new POST request based on the specified , and JSON . - /// - /// With this method, the property is automatically set to application/json. - /// - /// The URL of the request. - /// The query string of the request. - /// An instance of representing the POST body. - /// The formatting to be used when serializing . - public static HttpRequest Post(string url, IHttpQueryString? queryString, JToken body, Formatting formatting) { - return new HttpRequest(HttpMethod.Post, url, queryString, body, formatting); - } + /// + /// Initializes a new POST request based on the specified and JSON . + /// + /// With this method, the property is automatically set to application/json. + /// + /// The URL of the request. + /// An instance of representing the POST body. + /// The formatting to be used when serializing . + public static HttpRequest Post(string url, JToken body, Formatting formatting) { + return new HttpRequest(HttpMethod.Post, url, body, formatting); + } - /// - /// Initializes a new POST request based on the specified and XML . - /// - /// With this method, the property is automatically set to text/xml. - /// - /// The URL of the request. - /// An instance of representing the POST body. - public static HttpRequest Post(string url, XNode? body) { - return new HttpRequest(HttpMethod.Post, url).SetBody(body); - } + /// + /// Initializes a new POST request based on the specified , and JSON . + /// + /// With this method, the property is automatically set to application/json. + /// + /// The URL of the request. + /// The query string of the request. + /// An instance of representing the POST body. + public static HttpRequest Post(string url, IHttpQueryString? queryString, JToken body) { + return new HttpRequest(HttpMethod.Post, url, queryString, body); + } - /// - /// Initializes a new POST request based on the specified and XML . - /// - /// With this method, the property is automatically set to text/xml. - /// - /// The URL of the request. - /// An instance of representing the POST body. - /// The options to be used when serializing . - public static HttpRequest Post(string url, XNode? body, SaveOptions options) { - return new HttpRequest(HttpMethod.Post, url).SetBody(body, options); - } + /// + /// Initializes a new POST request based on the specified , and JSON . + /// + /// With this method, the property is automatically set to application/json. + /// + /// The URL of the request. + /// The query string of the request. + /// An instance of representing the POST body. + /// The formatting to be used when serializing . + public static HttpRequest Post(string url, IHttpQueryString? queryString, JToken body, Formatting formatting) { + return new HttpRequest(HttpMethod.Post, url, queryString, body, formatting); + } - /// - /// Initializes a new POST request based on the specified and XML . - /// - /// With this method, the property is automatically set to text/xml. - /// - /// The URL of the request. - /// The query string. - /// An instance of representing the POST body. - public static HttpRequest Post(string url, IHttpQueryString? queryString, XNode? body) { - return new HttpRequest(HttpMethod.Post, url, queryString).SetBody(body); - } + /// + /// Initializes a new POST request based on the specified and XML . + /// + /// With this method, the property is automatically set to text/xml. + /// + /// The URL of the request. + /// An instance of representing the POST body. + public static HttpRequest Post(string url, XNode? body) { + return new HttpRequest(HttpMethod.Post, url).SetBody(body); + } - /// - /// Initializes a new POST request based on the specified and XML . - /// - /// With this method, the property is automatically set to text/xml. - /// - /// The URL of the request. - /// The query string. - /// An instance of representing the POST body. - /// The options to be used when serializing . - public static HttpRequest Post(string url, IHttpQueryString? queryString, XNode? body, SaveOptions options) { - return new HttpRequest(HttpMethod.Post, url, queryString).SetBody(body, options); - } + /// + /// Initializes a new POST request based on the specified and XML . + /// + /// With this method, the property is automatically set to text/xml. + /// + /// The URL of the request. + /// An instance of representing the POST body. + /// The options to be used when serializing . + public static HttpRequest Post(string url, XNode? body, SaveOptions options) { + return new HttpRequest(HttpMethod.Post, url).SetBody(body, options); + } - /// - /// Initializes a new PUT request based on the specified . - /// - /// The URL of the request. - public static HttpRequest Put(string url) { - return new HttpRequest(HttpMethod.Put, url); - } + /// + /// Initializes a new POST request based on the specified and XML . + /// + /// With this method, the property is automatically set to text/xml. + /// + /// The URL of the request. + /// The query string. + /// An instance of representing the POST body. + public static HttpRequest Post(string url, IHttpQueryString? queryString, XNode? body) { + return new HttpRequest(HttpMethod.Post, url, queryString).SetBody(body); + } - /// - /// Initializes a new PUT request based on the specified . - /// - /// The URL of the request. - /// The query string of the request. - public static HttpRequest Put(string url, IHttpQueryString? queryString) { - return new HttpRequest(HttpMethod.Put, url, queryString); - } + /// + /// Initializes a new POST request based on the specified and XML . + /// + /// With this method, the property is automatically set to text/xml. + /// + /// The URL of the request. + /// The query string. + /// An instance of representing the POST body. + /// The options to be used when serializing . + public static HttpRequest Post(string url, IHttpQueryString? queryString, XNode? body, SaveOptions options) { + return new HttpRequest(HttpMethod.Post, url, queryString).SetBody(body, options); + } - /// - /// Initializes a new PUT request based on the specified and . - /// - /// The URL of the request. - /// The HTTP PUT data of the request. - public static HttpRequest Put(string url, IHttpPostData? postData) { - return new HttpRequest(HttpMethod.Put, url, postData); - } + /// + /// Initializes a new PUT request based on the specified . + /// + /// The URL of the request. + public static HttpRequest Put(string url) { + return new HttpRequest(HttpMethod.Put, url); + } - /// - /// Initializes a new PUT request based on the specified , and . - /// - /// The URL of the request. - /// The query string of the request. - /// The HTTP PUT data of the request. - public static HttpRequest Put(string url, IHttpQueryString? queryString, IHttpPostData? postData) { - return new HttpRequest(HttpMethod.Put, url, queryString, postData); - } + /// + /// Initializes a new PUT request based on the specified . + /// + /// The URL of the request. + /// The query string of the request. + public static HttpRequest Put(string url, IHttpQueryString? queryString) { + return new HttpRequest(HttpMethod.Put, url, queryString); + } - /// - /// Initializes a new PUT request based on the specified , , and . - /// - /// The URL of the request. - /// The query string of the request. - /// The content type of the request - eg. application/json. - /// The body of the request. - /// An instance of . - public static HttpRequest Put(string url, IHttpQueryString? queryString, string? contentType, string? body) { - return new HttpRequest(HttpMethod.Put, url, queryString).SetContentType(contentType).SetBody(body); - } + /// + /// Initializes a new PUT request based on the specified and . + /// + /// The URL of the request. + /// The HTTP PUT data of the request. + public static HttpRequest Put(string url, IHttpPostData? postData) { + return new HttpRequest(HttpMethod.Put, url, postData); + } - /// - /// Initializes a new PUT request based on the specified and JSON . - /// - /// With this method, the property is automatically set to application/json. - /// - /// The URL of the request. - /// An instance of representing the PUT body. - public static HttpRequest Put(string url, JToken body) { - return new HttpRequest(HttpMethod.Put, url, body); - } + /// + /// Initializes a new PUT request based on the specified , and . + /// + /// The URL of the request. + /// The query string of the request. + /// The HTTP PUT data of the request. + public static HttpRequest Put(string url, IHttpQueryString? queryString, IHttpPostData? postData) { + return new HttpRequest(HttpMethod.Put, url, queryString, postData); + } - /// - /// Initializes a new PUT request based on the specified and JSON . - /// - /// With this method, the property is automatically set to application/json. - /// - /// The URL of the request. - /// An instance of representing the POST body. - /// The formatting to be used when serializing . - public static HttpRequest Put(string url, JToken body, Formatting formatting) { - return new HttpRequest(HttpMethod.Put, url, body, formatting); - } + /// + /// Initializes a new PUT request based on the specified , , and . + /// + /// The URL of the request. + /// The query string of the request. + /// The content type of the request - eg. application/json. + /// The body of the request. + /// An instance of . + public static HttpRequest Put(string url, IHttpQueryString? queryString, string? contentType, string? body) { + return new HttpRequest(HttpMethod.Put, url, queryString).SetContentType(contentType).SetBody(body); + } - /// - /// Initializes a new PUT request based on the specified , and JSON . - /// - /// With this method, the property is automatically set to application/json. - /// - /// The URL of the request. - /// The query string of the request. - /// An instance of representing the PUT body. - public static HttpRequest Put(string url, IHttpQueryString? queryString, JToken body) { - return new HttpRequest(HttpMethod.Put, url, queryString, body); - } + /// + /// Initializes a new PUT request based on the specified and JSON . + /// + /// With this method, the property is automatically set to application/json. + /// + /// The URL of the request. + /// An instance of representing the PUT body. + public static HttpRequest Put(string url, JToken body) { + return new HttpRequest(HttpMethod.Put, url, body); + } - /// - /// Initializes a new PUT request based on the specified , and JSON . - /// - /// With this method, the property is automatically set to application/json. - /// - /// The URL of the request. - /// The query string of the request. - /// An instance of representing the POST body. - /// The formatting to be used when serializing . - public static HttpRequest Put(string url, IHttpQueryString? queryString, JToken body, Formatting formatting) { - return new HttpRequest(HttpMethod.Put, url, queryString, body, formatting); - } + /// + /// Initializes a new PUT request based on the specified and JSON . + /// + /// With this method, the property is automatically set to application/json. + /// + /// The URL of the request. + /// An instance of representing the POST body. + /// The formatting to be used when serializing . + public static HttpRequest Put(string url, JToken body, Formatting formatting) { + return new HttpRequest(HttpMethod.Put, url, body, formatting); + } - /// - /// Initializes a new PUT request based on the specified and XML . - /// - /// With this method, the property is automatically set to text/xml. - /// - /// The URL of the request. - /// An instance of representing the POST body. - public static HttpRequest Put(string url, XNode body) { - return new HttpRequest(HttpMethod.Put, url).SetBody(body); - } + /// + /// Initializes a new PUT request based on the specified , and JSON . + /// + /// With this method, the property is automatically set to application/json. + /// + /// The URL of the request. + /// The query string of the request. + /// An instance of representing the PUT body. + public static HttpRequest Put(string url, IHttpQueryString? queryString, JToken body) { + return new HttpRequest(HttpMethod.Put, url, queryString, body); + } - /// - /// Initializes a new PUT request based on the specified and XML . - /// - /// With this method, the property is automatically set to text/xml. - /// - /// The URL of the request. - /// An instance of representing the POST body. - /// The options to be used when serializing . - public static HttpRequest Put(string url, XNode body, SaveOptions options) { - return new HttpRequest(HttpMethod.Put, url).SetBody(body, options); - } + /// + /// Initializes a new PUT request based on the specified , and JSON . + /// + /// With this method, the property is automatically set to application/json. + /// + /// The URL of the request. + /// The query string of the request. + /// An instance of representing the POST body. + /// The formatting to be used when serializing . + public static HttpRequest Put(string url, IHttpQueryString? queryString, JToken body, Formatting formatting) { + return new HttpRequest(HttpMethod.Put, url, queryString, body, formatting); + } - /// - /// Initializes a new PUT request based on the specified and XML . - /// - /// With this method, the property is automatically set to text/xml. - /// - /// The URL of the request. - /// The query string. - /// An instance of representing the POST body. - public static HttpRequest Put(string url, IHttpQueryString? queryString, XNode body) { - return new HttpRequest(HttpMethod.Put, url, queryString).SetBody(body); - } + /// + /// Initializes a new PUT request based on the specified and XML . + /// + /// With this method, the property is automatically set to text/xml. + /// + /// The URL of the request. + /// An instance of representing the POST body. + public static HttpRequest Put(string url, XNode body) { + return new HttpRequest(HttpMethod.Put, url).SetBody(body); + } - /// - /// Initializes a new PUT request based on the specified and XML . - /// - /// With this method, the property is automatically set to text/xml. - /// - /// The URL of the request. - /// The query string. - /// An instance of representing the POST body. - /// The options to be used when serializing . - public static HttpRequest Put(string url, IHttpQueryString? queryString, XNode body, SaveOptions options) { - return new HttpRequest(HttpMethod.Put, url, queryString).SetBody(body, options); - } + /// + /// Initializes a new PUT request based on the specified and XML . + /// + /// With this method, the property is automatically set to text/xml. + /// + /// The URL of the request. + /// An instance of representing the POST body. + /// The options to be used when serializing . + public static HttpRequest Put(string url, XNode body, SaveOptions options) { + return new HttpRequest(HttpMethod.Put, url).SetBody(body, options); + } - /// - /// Initializes a new PATCH request based on the specified . - /// - /// The URL of the request. - public static HttpRequest Patch(string url) { - return new HttpRequest(HttpMethod.Patch, url); - } + /// + /// Initializes a new PUT request based on the specified and XML . + /// + /// With this method, the property is automatically set to text/xml. + /// + /// The URL of the request. + /// The query string. + /// An instance of representing the POST body. + public static HttpRequest Put(string url, IHttpQueryString? queryString, XNode body) { + return new HttpRequest(HttpMethod.Put, url, queryString).SetBody(body); + } - /// - /// Initializes a new PATCH request based on the specified . - /// - /// The URL of the request. - /// The query string of the request. - public static HttpRequest Patch(string url, IHttpQueryString? queryString) { - return new HttpRequest(HttpMethod.Patch, url, queryString); - } + /// + /// Initializes a new PUT request based on the specified and XML . + /// + /// With this method, the property is automatically set to text/xml. + /// + /// The URL of the request. + /// The query string. + /// An instance of representing the POST body. + /// The options to be used when serializing . + public static HttpRequest Put(string url, IHttpQueryString? queryString, XNode body, SaveOptions options) { + return new HttpRequest(HttpMethod.Put, url, queryString).SetBody(body, options); + } - /// - /// Initializes a new PATCH request based on the specified and . - /// - /// The URL of the request. - /// The HTTP PATCH data of the request. - public static HttpRequest Patch(string url, IHttpPostData? postData) { - return new HttpRequest(HttpMethod.Patch, url, postData); - } + /// + /// Initializes a new PATCH request based on the specified . + /// + /// The URL of the request. + public static HttpRequest Patch(string url) { + return new HttpRequest(HttpMethod.Patch, url); + } - /// - /// Initializes a new PATCH request based on the specified , and . - /// - /// The URL of the request. - /// The query string of the request. - /// The HTTP PATCH data of the request. - public static HttpRequest Patch(string url, IHttpQueryString? queryString, IHttpPostData? postData) { - return new HttpRequest(HttpMethod.Patch, url, queryString, postData); - } + /// + /// Initializes a new PATCH request based on the specified . + /// + /// The URL of the request. + /// The query string of the request. + public static HttpRequest Patch(string url, IHttpQueryString? queryString) { + return new HttpRequest(HttpMethod.Patch, url, queryString); + } - /// - /// Initializes a new PATCH request based on the specified , , and . - /// - /// The URL of the request. - /// The query string of the request. - /// The content type of the request - eg. application/json. - /// The body of the request. - /// An instance of . - public static HttpRequest Patch(string url, IHttpQueryString? queryString, string? contentType, string? body) { - return new HttpRequest(HttpMethod.Patch, url, queryString).SetContentType(contentType).SetBody(body); - } + /// + /// Initializes a new PATCH request based on the specified and . + /// + /// The URL of the request. + /// The HTTP PATCH data of the request. + public static HttpRequest Patch(string url, IHttpPostData? postData) { + return new HttpRequest(HttpMethod.Patch, url, postData); + } - /// - /// Initializes a new PATCH request based on the specified and JSON . - /// - /// With this method, the property is automatically set to application/json. - /// - /// The URL of the request. - /// An instance of representing the PATCH body. - public static HttpRequest Patch(string url, JToken body) { - return new HttpRequest(HttpMethod.Patch, url, body); - } + /// + /// Initializes a new PATCH request based on the specified , and . + /// + /// The URL of the request. + /// The query string of the request. + /// The HTTP PATCH data of the request. + public static HttpRequest Patch(string url, IHttpQueryString? queryString, IHttpPostData? postData) { + return new HttpRequest(HttpMethod.Patch, url, queryString, postData); + } - /// - /// Initializes a new PATCH request based on the specified and JSON . - /// - /// With this method, the property is automatically set to application/json. - /// - /// The URL of the request. - /// An instance of representing the POST body. - /// The formatting to be used when serializing . - public static HttpRequest Patch(string url, JToken body, Formatting formatting) { - return new HttpRequest(HttpMethod.Patch, url, body, formatting); - } + /// + /// Initializes a new PATCH request based on the specified , , and . + /// + /// The URL of the request. + /// The query string of the request. + /// The content type of the request - eg. application/json. + /// The body of the request. + /// An instance of . + public static HttpRequest Patch(string url, IHttpQueryString? queryString, string? contentType, string? body) { + return new HttpRequest(HttpMethod.Patch, url, queryString).SetContentType(contentType).SetBody(body); + } - /// - /// Initializes a new PATCH request based on the specified , and JSON . - /// - /// With this method, the property is automatically set to application/json. - /// - /// The URL of the request. - /// The query string of the request. - /// An instance of representing the PATCH body. - public static HttpRequest Patch(string url, IHttpQueryString? queryString, JToken body) { - return new HttpRequest(HttpMethod.Patch, url, queryString, body); - } + /// + /// Initializes a new PATCH request based on the specified and JSON . + /// + /// With this method, the property is automatically set to application/json. + /// + /// The URL of the request. + /// An instance of representing the PATCH body. + public static HttpRequest Patch(string url, JToken body) { + return new HttpRequest(HttpMethod.Patch, url, body); + } - /// - /// Initializes a new PATCH request based on the specified , and JSON . - /// - /// With this method, the property is automatically set to application/json. - /// - /// The URL of the request. - /// The query string of the request. - /// An instance of representing the POST body. - /// The formatting to be used when serializing . - public static HttpRequest Patch(string url, IHttpQueryString? queryString, JToken body, Formatting formatting) { - return new HttpRequest(HttpMethod.Patch, url, queryString, body, formatting); - } + /// + /// Initializes a new PATCH request based on the specified and JSON . + /// + /// With this method, the property is automatically set to application/json. + /// + /// The URL of the request. + /// An instance of representing the POST body. + /// The formatting to be used when serializing . + public static HttpRequest Patch(string url, JToken body, Formatting formatting) { + return new HttpRequest(HttpMethod.Patch, url, body, formatting); + } - /// - /// Initializes a new PATCH request based on the specified and XML . - /// - /// With this method, the property is automatically set to text/xml. - /// - /// The URL of the request. - /// An instance of representing the POST body. - public static HttpRequest Patch(string url, XNode body) { - return new HttpRequest(HttpMethod.Patch, url).SetBody(body); - } + /// + /// Initializes a new PATCH request based on the specified , and JSON . + /// + /// With this method, the property is automatically set to application/json. + /// + /// The URL of the request. + /// The query string of the request. + /// An instance of representing the PATCH body. + public static HttpRequest Patch(string url, IHttpQueryString? queryString, JToken body) { + return new HttpRequest(HttpMethod.Patch, url, queryString, body); + } - /// - /// Initializes a new PATCH request based on the specified and XML . - /// - /// With this method, the property is automatically set to text/xml. - /// - /// The URL of the request. - /// An instance of representing the POST body. - /// The options to be used when serializing . - public static HttpRequest Patch(string url, XNode body, SaveOptions options) { - return new HttpRequest(HttpMethod.Patch, url).SetBody(body, options); - } + /// + /// Initializes a new PATCH request based on the specified , and JSON . + /// + /// With this method, the property is automatically set to application/json. + /// + /// The URL of the request. + /// The query string of the request. + /// An instance of representing the POST body. + /// The formatting to be used when serializing . + public static HttpRequest Patch(string url, IHttpQueryString? queryString, JToken body, Formatting formatting) { + return new HttpRequest(HttpMethod.Patch, url, queryString, body, formatting); + } - /// - /// Initializes a new PATCH request based on the specified and XML . - /// - /// With this method, the property is automatically set to text/xml. - /// - /// The URL of the request. - /// The query string. - /// An instance of representing the POST body. - public static HttpRequest Patch(string url, IHttpQueryString? queryString, XNode body) { - return new HttpRequest(HttpMethod.Patch, url, queryString).SetBody(body); - } + /// + /// Initializes a new PATCH request based on the specified and XML . + /// + /// With this method, the property is automatically set to text/xml. + /// + /// The URL of the request. + /// An instance of representing the POST body. + public static HttpRequest Patch(string url, XNode body) { + return new HttpRequest(HttpMethod.Patch, url).SetBody(body); + } - /// - /// Initializes a new PATCH request based on the specified and XML . - /// - /// With this method, the property is automatically set to text/xml. - /// - /// The URL of the request. - /// The query string. - /// An instance of representing the POST body. - /// The options to be used when serializing . - public static HttpRequest Patch(string url, IHttpQueryString? queryString, XNode body, SaveOptions options) { - return new HttpRequest(HttpMethod.Patch, url, queryString).SetBody(body, options); - } + /// + /// Initializes a new PATCH request based on the specified and XML . + /// + /// With this method, the property is automatically set to text/xml. + /// + /// The URL of the request. + /// An instance of representing the POST body. + /// The options to be used when serializing . + public static HttpRequest Patch(string url, XNode body, SaveOptions options) { + return new HttpRequest(HttpMethod.Patch, url).SetBody(body, options); + } - /// - /// Initializes a new DELETE request based on the specified . - /// - /// The URL of the request. The query string may be part of the specified URL or via the property. - public static HttpRequest Delete(string url) { - return new HttpRequest(HttpMethod.Delete, url); - } + /// + /// Initializes a new PATCH request based on the specified and XML . + /// + /// With this method, the property is automatically set to text/xml. + /// + /// The URL of the request. + /// The query string. + /// An instance of representing the POST body. + public static HttpRequest Patch(string url, IHttpQueryString? queryString, XNode body) { + return new HttpRequest(HttpMethod.Patch, url, queryString).SetBody(body); + } - /// - /// Initializes a new DELETE request based on the specified and . - /// - /// The URL of the request. - /// The query string of the request. - public static HttpRequest Delete(string url, IHttpQueryString? queryString) { - return new HttpRequest(HttpMethod.Delete, url, queryString); - } + /// + /// Initializes a new PATCH request based on the specified and XML . + /// + /// With this method, the property is automatically set to text/xml. + /// + /// The URL of the request. + /// The query string. + /// An instance of representing the POST body. + /// The options to be used when serializing . + public static HttpRequest Patch(string url, IHttpQueryString? queryString, XNode body, SaveOptions options) { + return new HttpRequest(HttpMethod.Patch, url, queryString).SetBody(body, options); + } - #endregion + /// + /// Initializes a new DELETE request based on the specified . + /// + /// The URL of the request. The query string may be part of the specified URL or via the property. + public static HttpRequest Delete(string url) { + return new HttpRequest(HttpMethod.Delete, url); + } + /// + /// Initializes a new DELETE request based on the specified and . + /// + /// The URL of the request. + /// The query string of the request. + public static HttpRequest Delete(string url, IHttpQueryString? queryString) { + return new HttpRequest(HttpMethod.Delete, url, queryString); } + #endregion + } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/HttpRequestExtensions.cs b/src/Skybrud.Essentials.Http/HttpRequestExtensions.cs index e62e70b..a18d6f4 100644 --- a/src/Skybrud.Essentials.Http/HttpRequestExtensions.cs +++ b/src/Skybrud.Essentials.Http/HttpRequestExtensions.cs @@ -5,243 +5,241 @@ using Skybrud.Essentials.Security; using System.Diagnostics.CodeAnalysis; -namespace Skybrud.Essentials.Http { - - /// - /// Various extension methods for . - /// - public static class HttpRequestExtensions { - - /// - /// Sets the property of . - /// - /// The type of the request - eg. . - /// The request. - /// The new HTTP method of the request. - /// The specified as an instance of . - [return: NotNullIfNotNull("request")] - public static T? SetMethod(this T? request, HttpMethod method) where T : IHttpRequest { - if (request != null) request.Method = method; - return request; - } - - /// - /// Sets the property of . - /// - /// The type of the request - eg. . - /// The request. - /// The new URL of the request. - /// The specified as an instance of . - [return: NotNullIfNotNull("request")] - public static T? SetUrl(this T? request, string url) where T : IHttpRequest { - if (request != null) request.Url = url; - return request; - } - - /// - /// Sets the property of . - /// - /// The type of the request - eg. . - /// The request. - /// The new query string of the request. - /// The specified as an instance of . - [return: NotNullIfNotNull("request")] - public static T? SetQueryString(this T? request, IHttpQueryString? queryString) where T : IHttpRequest { - if (request != null) request.QueryString = queryString!; - return request; - } - - /// - /// Sets the property of . - /// - /// The type of the request - eg. . - /// The request. - /// The new POST data of the request. - /// The specified as an instance of . - [return: NotNullIfNotNull("request")] - public static T? SetPostData(this T? request, IHttpPostData? postData) where T : IHttpRequest { - if (request != null) request.PostData = postData!; - return request; - } - - /// - /// Sets the property of . - /// - /// The type of the request - eg. . - /// The request. - /// The new body of the request. - /// The specified as an instance of . - [return: NotNullIfNotNull("request")] - public static T? SetBody(this T? request, string? body) where T : IHttpRequest { - if (request != null) request.Body = body; - return request; - } - - /// - /// Sets the property of . - /// - /// The type of the request - eg. . - /// The request. - /// The new body of the request. - /// The new content type of the request. - /// The specified as an instance of . - [return: NotNullIfNotNull("request")] - public static T? SetBody(this T? request, string? body, string? contentType) where T : IHttpRequest { - if (request != null) request.Body = body; - if (request != null) request.ContentType = contentType; - return request; - } - - /// - /// Sets the property of . - /// - /// The type of the request - eg. . - /// The request. - /// The new body of the request. - /// The specified as an instance of . - [return: NotNullIfNotNull("request")] - public static T? SetBody(this T? request, byte[]? body) where T : HttpRequest { - if (request != null) request.BinaryBody = body; - return request; - } - - /// - /// Sets the property of . - /// - /// The type of the request - eg. . - /// The request. - /// The new body of the request. - /// The new content type of the request. - /// The specified as an instance of . - [return: NotNullIfNotNull("request")] - public static T? SetBody(this T? request, byte[]? body, string? contentType) where T : HttpRequest { - if (request != null) request.BinaryBody = body; - if (request != null) request.ContentType = contentType; - return request; - } - - /// - /// Sets the property of . - /// - /// The type of the request - eg. . - /// The request. - /// The new body of the request. - /// The specified as an instance of . - [return: NotNullIfNotNull("request")] - public static T? SetBody(this T? request, JToken? body) where T : IHttpRequest { - return SetBody(request, body, Formatting.None); - } - - /// - /// Sets the property of . - /// - /// The type of the request - eg. . - /// The request. - /// The new body of the request. - /// The formatting to be used when serializing . - /// The specified as an instance of . - [return: NotNullIfNotNull("request")] - public static T? SetBody(this T? request, JToken? body, Formatting formatting) where T : IHttpRequest { - if (request == null) return default; - request.ContentType = HttpConstants.ApplicationJson; - request.Body = body?.ToString(formatting); - return request; - } - - /// - /// Sets the Accept header of . - /// - /// The type of the request - eg. . - /// The request. - /// The value of the header. - /// The specified as an instance of . - [return: NotNullIfNotNull("request")] - public static T? SetAcceptHeader(this T? request, string? value) where T : IHttpRequest { - if (request != null) request.Accept = value; - return request; - } - - /// - /// Sets the Accept header of . - /// - /// The type of the request - eg. . - /// The request. - /// The value of the header. - /// The specified as an instance of . - [return: NotNullIfNotNull("request")] - public static T? SetAcceptHeader(this T? request, IEnumerable? value) where T : IHttpRequest { - if (request != null) request.Accept = value == null ? null : string.Join(",", value); - return request; - } - - /// - /// Sets the Authorization header of . - /// - /// The type of the request - eg. . - /// The request. - /// The value of the header. - /// The specified as an instance of . - [return: NotNullIfNotNull("request")] - public static T? SetAuthorizationHeader(this T? request, string? value) where T : IHttpRequest { - if (request != null) request.Headers.Authorization = value; - return request; - } - - /// - /// Sets the Authorization header of to use Basic - /// authentication based on the specified and . - /// - /// The type of the request - eg. . - /// The request. - /// The username. - /// The password. - /// The specified as an instance of . - [return: NotNullIfNotNull("request")] - public static T? SetAuthorizationBasic(this T? request, string username, string password) where T : IHttpRequest { - if (request != null) request.Headers.Authorization = $"Basic {SecurityUtils.Base64Encode($"{username}:{password}")}"; - return request; - } - - /// - /// Sets the Authorization header of using the specified - /// Bearer . - /// - /// The type of the request - eg. . - /// The request. - /// The bearer token. - /// The specified as an instance of . - [return: NotNullIfNotNull("request")] - public static T? SetAuthorizationBearer(this T? request, string token) where T : IHttpRequest { - if (request != null) request.Headers.Authorization = $"Bearer {token}"; - return request; - } - - /// - /// Sets the ContentType header of . - /// - /// The type of the request - eg. . - /// The request. - /// The value of the header. - /// The specified as an instance of . - [return: NotNullIfNotNull("request")] - public static T? SetContentType(this T? request, string? value) where T : IHttpRequest { - if (request != null) request.ContentType = value; - return request; - } - - /// - /// Sets the SetUserAgent header of . - /// - /// The type of the request - eg. . - /// The request. - /// The value of the header. - /// The specified as an instance of . - [return: NotNullIfNotNull("request")] - public static T? SetUserAgent(this T? request, string? value) where T : IHttpRequest { - if (request != null) request.UserAgent = value; - return request; - } +namespace Skybrud.Essentials.Http; +/// +/// Various extension methods for . +/// +public static class HttpRequestExtensions { + + /// + /// Sets the property of . + /// + /// The type of the request - eg. . + /// The request. + /// The new HTTP method of the request. + /// The specified as an instance of . + [return: NotNullIfNotNull("request")] + public static T? SetMethod(this T? request, HttpMethod method) where T : IHttpRequest { + if (request != null) request.Method = method; + return request; + } + + /// + /// Sets the property of . + /// + /// The type of the request - eg. . + /// The request. + /// The new URL of the request. + /// The specified as an instance of . + [return: NotNullIfNotNull("request")] + public static T? SetUrl(this T? request, string url) where T : IHttpRequest { + if (request != null) request.Url = url; + return request; + } + + /// + /// Sets the property of . + /// + /// The type of the request - eg. . + /// The request. + /// The new query string of the request. + /// The specified as an instance of . + [return: NotNullIfNotNull("request")] + public static T? SetQueryString(this T? request, IHttpQueryString? queryString) where T : IHttpRequest { + if (request != null) request.QueryString = queryString!; + return request; + } + + /// + /// Sets the property of . + /// + /// The type of the request - eg. . + /// The request. + /// The new POST data of the request. + /// The specified as an instance of . + [return: NotNullIfNotNull("request")] + public static T? SetPostData(this T? request, IHttpPostData? postData) where T : IHttpRequest { + if (request != null) request.PostData = postData!; + return request; + } + + /// + /// Sets the property of . + /// + /// The type of the request - eg. . + /// The request. + /// The new body of the request. + /// The specified as an instance of . + [return: NotNullIfNotNull("request")] + public static T? SetBody(this T? request, string? body) where T : IHttpRequest { + if (request != null) request.Body = body; + return request; + } + + /// + /// Sets the property of . + /// + /// The type of the request - eg. . + /// The request. + /// The new body of the request. + /// The new content type of the request. + /// The specified as an instance of . + [return: NotNullIfNotNull("request")] + public static T? SetBody(this T? request, string? body, string? contentType) where T : IHttpRequest { + if (request != null) request.Body = body; + if (request != null) request.ContentType = contentType; + return request; + } + + /// + /// Sets the property of . + /// + /// The type of the request - eg. . + /// The request. + /// The new body of the request. + /// The specified as an instance of . + [return: NotNullIfNotNull("request")] + public static T? SetBody(this T? request, byte[]? body) where T : HttpRequest { + if (request != null) request.BinaryBody = body; + return request; + } + + /// + /// Sets the property of . + /// + /// The type of the request - eg. . + /// The request. + /// The new body of the request. + /// The new content type of the request. + /// The specified as an instance of . + [return: NotNullIfNotNull("request")] + public static T? SetBody(this T? request, byte[]? body, string? contentType) where T : HttpRequest { + if (request != null) request.BinaryBody = body; + if (request != null) request.ContentType = contentType; + return request; + } + + /// + /// Sets the property of . + /// + /// The type of the request - eg. . + /// The request. + /// The new body of the request. + /// The specified as an instance of . + [return: NotNullIfNotNull("request")] + public static T? SetBody(this T? request, JToken? body) where T : IHttpRequest { + return SetBody(request, body, Formatting.None); + } + + /// + /// Sets the property of . + /// + /// The type of the request - eg. . + /// The request. + /// The new body of the request. + /// The formatting to be used when serializing . + /// The specified as an instance of . + [return: NotNullIfNotNull("request")] + public static T? SetBody(this T? request, JToken? body, Formatting formatting) where T : IHttpRequest { + if (request == null) return default; + request.ContentType = HttpConstants.ApplicationJson; + request.Body = body?.ToString(formatting); + return request; + } + + /// + /// Sets the Accept header of . + /// + /// The type of the request - eg. . + /// The request. + /// The value of the header. + /// The specified as an instance of . + [return: NotNullIfNotNull("request")] + public static T? SetAcceptHeader(this T? request, string? value) where T : IHttpRequest { + if (request != null) request.Accept = value; + return request; + } + + /// + /// Sets the Accept header of . + /// + /// The type of the request - eg. . + /// The request. + /// The value of the header. + /// The specified as an instance of . + [return: NotNullIfNotNull("request")] + public static T? SetAcceptHeader(this T? request, IEnumerable? value) where T : IHttpRequest { + if (request != null) request.Accept = value == null ? null : string.Join(",", value); + return request; + } + + /// + /// Sets the Authorization header of . + /// + /// The type of the request - eg. . + /// The request. + /// The value of the header. + /// The specified as an instance of . + [return: NotNullIfNotNull("request")] + public static T? SetAuthorizationHeader(this T? request, string? value) where T : IHttpRequest { + if (request != null) request.Headers.Authorization = value; + return request; + } + + /// + /// Sets the Authorization header of to use Basic + /// authentication based on the specified and . + /// + /// The type of the request - eg. . + /// The request. + /// The username. + /// The password. + /// The specified as an instance of . + [return: NotNullIfNotNull("request")] + public static T? SetAuthorizationBasic(this T? request, string username, string password) where T : IHttpRequest { + if (request != null) request.Headers.Authorization = $"Basic {SecurityUtils.Base64Encode($"{username}:{password}")}"; + return request; + } + + /// + /// Sets the Authorization header of using the specified + /// Bearer . + /// + /// The type of the request - eg. . + /// The request. + /// The bearer token. + /// The specified as an instance of . + [return: NotNullIfNotNull("request")] + public static T? SetAuthorizationBearer(this T? request, string token) where T : IHttpRequest { + if (request != null) request.Headers.Authorization = $"Bearer {token}"; + return request; + } + + /// + /// Sets the ContentType header of . + /// + /// The type of the request - eg. . + /// The request. + /// The value of the header. + /// The specified as an instance of . + [return: NotNullIfNotNull("request")] + public static T? SetContentType(this T? request, string? value) where T : IHttpRequest { + if (request != null) request.ContentType = value; + return request; + } + + /// + /// Sets the SetUserAgent header of . + /// + /// The type of the request - eg. . + /// The request. + /// The value of the header. + /// The specified as an instance of . + [return: NotNullIfNotNull("request")] + public static T? SetUserAgent(this T? request, string? value) where T : IHttpRequest { + if (request != null) request.UserAgent = value; + return request; } } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/HttpRequestXmlExtensions.cs b/src/Skybrud.Essentials.Http/HttpRequestXmlExtensions.cs index 146682a..959732a 100644 --- a/src/Skybrud.Essentials.Http/HttpRequestXmlExtensions.cs +++ b/src/Skybrud.Essentials.Http/HttpRequestXmlExtensions.cs @@ -1,71 +1,69 @@ using System.Diagnostics.CodeAnalysis; using System.Xml.Linq; -namespace Skybrud.Essentials.Http { +namespace Skybrud.Essentials.Http; + +/// +/// Various extension methods for . +/// +public static class HttpRequestXmlExtensions { /// - /// Various extension methods for . + /// Sets the property of . /// - public static class HttpRequestXmlExtensions { - - /// - /// Sets the property of . - /// - /// The type of the request - eg. . - /// The request. - /// The new body of the request. - /// The specified as an instance of . - [return: NotNullIfNotNull("request")] - public static T? SetBody(this T? request, XNode? body) where T : IHttpRequest { - return SetBody(request, body, SaveOptions.None); - } - - /// - /// Sets the property of . - /// - /// The type of the request - eg. . - /// The request. - /// The new body of the request. - /// The options to be used when serializing . - /// The specified as an instance of . - [return: NotNullIfNotNull("request")] - public static T? SetBody(this T? request, XNode? body, SaveOptions options) where T : IHttpRequest { - if (request == null) return default; - request.ContentType = HttpConstants.TextXml; - request.Body = body?.ToString(options); - return request; - } + /// The type of the request - eg. . + /// The request. + /// The new body of the request. + /// The specified as an instance of . + [return: NotNullIfNotNull("request")] + public static T? SetBody(this T? request, XNode? body) where T : IHttpRequest { + return SetBody(request, body, SaveOptions.None); + } - /// - /// Sets the property of . - /// - /// The type of the request - eg. . - /// The request. - /// The new content type of the request. - /// The new body of the request. - /// The specified as an instance of . - [return: NotNullIfNotNull("request")] - public static T? SetBody(this T? request, string? contentType, XNode? body) where T : IHttpRequest { - return SetBody(request, contentType, body, SaveOptions.None); - } + /// + /// Sets the property of . + /// + /// The type of the request - eg. . + /// The request. + /// The new body of the request. + /// The options to be used when serializing . + /// The specified as an instance of . + [return: NotNullIfNotNull("request")] + public static T? SetBody(this T? request, XNode? body, SaveOptions options) where T : IHttpRequest { + if (request == null) return default; + request.ContentType = HttpConstants.TextXml; + request.Body = body?.ToString(options); + return request; + } - /// - /// Sets the property of . - /// - /// The type of the request - eg. . - /// The request. - /// The new content type of the request. - /// The new body of the request. - /// The options to be used when serializing . - /// The specified as an instance of . - [return: NotNullIfNotNull("request")] - public static T? SetBody(this T? request, string? contentType, XNode? body, SaveOptions options) where T : IHttpRequest { - if (request == null) return default; - request.ContentType = contentType; - request.Body = body?.ToString(options); - return request; - } + /// + /// Sets the property of . + /// + /// The type of the request - eg. . + /// The request. + /// The new content type of the request. + /// The new body of the request. + /// The specified as an instance of . + [return: NotNullIfNotNull("request")] + public static T? SetBody(this T? request, string? contentType, XNode? body) where T : IHttpRequest { + return SetBody(request, contentType, body, SaveOptions.None); + } + /// + /// Sets the property of . + /// + /// The type of the request - eg. . + /// The request. + /// The new content type of the request. + /// The new body of the request. + /// The options to be used when serializing . + /// The specified as an instance of . + [return: NotNullIfNotNull("request")] + public static T? SetBody(this T? request, string? contentType, XNode? body, SaveOptions options) where T : IHttpRequest { + if (request == null) return default; + request.ContentType = contentType; + request.Body = body?.ToString(options); + return request; } } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/HttpResponse.cs b/src/Skybrud.Essentials.Http/HttpResponse.cs index fce262a..ddd5da8 100644 --- a/src/Skybrud.Essentials.Http/HttpResponse.cs +++ b/src/Skybrud.Essentials.Http/HttpResponse.cs @@ -10,207 +10,205 @@ #pragma warning disable SYSLIB0001 -namespace Skybrud.Essentials.Http { - - /// - /// Wrapper class for . - /// - public class HttpResponse : IHttpResponse { - - private HttpHeaderCollection? _headers; - private byte[]? _binary; - private string? _body; - - #region Properties - - /// - /// Gets a reference to the that resulted in the response. - /// - public IHttpRequest? Request { get; } - - /// - /// Gets a reference to the underlying . - /// - public HttpWebResponse Response { get; } - - /// - /// Gets the status code returned by the server. - /// - public HttpStatusCode StatusCode => Response.StatusCode; - - /// - /// Gets the status description returned by the server. - /// - public string StatusDescription => Response.StatusDescription; - - /// - /// Gets the HTTP method of the request to the server. - /// - public string Method => Response.Method; - - /// - /// Gets the content type of the response. - /// - public string ContentType => Response.ContentType; - - /// - /// Gets a collections of headers returned by the server. - /// - public IHttpHeaderCollection Headers => _headers ??= new HttpHeaderCollection(Response.Headers); - - /// - /// Gets the URI of the response (eg. if the request was redirected). - /// - public Uri ResponseUri => Response.ResponseUri; - - /// - /// Gets a reference to the . The underlying doesn't - /// explicitly expode the encoding of the response, so the value of this property is a "best guess" based on - /// the HTTP headers of the response. - /// - public Encoding Encoding { get; private set; } - - /// - /// Gets the response body as a raw string. - /// - public string Body { - get { - if (_body == null) ReadResponseBody(); - return _body!; - } - } +namespace Skybrud.Essentials.Http; - /// - /// Gets the response body as an array of . - /// - public byte[] BinaryBody { - get { - if (_binary == null) ReadResponseBody(); - return _binary!; - } - } +/// +/// Wrapper class for . +/// +public class HttpResponse : IHttpResponse { - #endregion + private HttpHeaderCollection? _headers; + private byte[]? _binary; + private string? _body; - #region Constructor + #region Properties - private HttpResponse(IHttpRequest? request, HttpWebResponse response) { - Request = request; - Response = response; - Encoding = DetectResponseEncoding(); - } + /// + /// Gets a reference to the that resulted in the response. + /// + public IHttpRequest? Request { get; } - #endregion - - #region Member methods - - /// - /// Attemps to detect the encoding of the response body. The result is currently only based on the - /// Content-Type HTTP header. If an encoding can't be detected, UTF8 will be used as fallback. - /// - /// The of the response body. - private Encoding DetectResponseEncoding() { - - // Information in the header is seperated by ";" - foreach (string piece in ContentType.Split(';')) { - - // Search for the charset - Match regex = Regex.Match(piece.Trim().ToLowerInvariant(), "^charset=(.+?)$"); - - if (regex.Success) { - switch (regex.Groups[1].Value) { - case "us-ascii": return Encoding.ASCII; - case "iso-8859-1": - case "windows-1252": return Encoding.GetEncoding(1252); - case "utf-7": return Encoding.UTF7; - case "utf-8": return Encoding.UTF8; - case "utf-16": return Encoding.Unicode; - case "utf-32": return Encoding.UTF32; - } - } + /// + /// Gets a reference to the underlying . + /// + public HttpWebResponse Response { get; } - } + /// + /// Gets the status code returned by the server. + /// + public HttpStatusCode StatusCode => Response.StatusCode; + + /// + /// Gets the status description returned by the server. + /// + public string StatusDescription => Response.StatusDescription; + + /// + /// Gets the HTTP method of the request to the server. + /// + public string Method => Response.Method; - // Use UTF8 as fallback - return Encoding.UTF8; + /// + /// Gets the content type of the response. + /// + public string ContentType => Response.ContentType; + /// + /// Gets a collections of headers returned by the server. + /// + public IHttpHeaderCollection Headers => _headers ??= new HttpHeaderCollection(Response.Headers); + + /// + /// Gets the URI of the response (eg. if the request was redirected). + /// + public Uri ResponseUri => Response.ResponseUri; + + /// + /// Gets a reference to the . The underlying doesn't + /// explicitly expode the encoding of the response, so the value of this property is a "best guess" based on + /// the HTTP headers of the response. + /// + public Encoding Encoding { get; private set; } + + /// + /// Gets the response body as a raw string. + /// + public string Body { + get { + if (_body == null) ReadResponseBody(); + return _body!; } + } - /// - /// Reads the response body from the response stream. The method will read the response body using an instance - /// of with a buffer size of 4096 bytes. - /// - private void ReadResponseBody() { - - // If "binary" isn't NULL, we have already read the response body - // once, and the stream is therefore already disposed - if (_binary != null) return; - - // Get a reference to the response stream (and dispose it once we're done) - using (Stream? stream = Response.GetResponseStream()) { - - // The stream really shouldn't be NULL, but just to be sure - if (stream == null) return; - - // Read the response stream into a binary array - using (BinaryReader reader = new(stream)) { - byte[] allBytes; - const int bufferSize = 4096; - using (var ms = new MemoryStream()) { - byte[] buffer = new byte[bufferSize]; - int count; - while ((count = reader.Read(buffer, 0, buffer.Length)) != 0) - ms.Write(buffer, 0, count); - allBytes = ms.ToArray(); - } - _binary = allBytes; - } + /// + /// Gets the response body as an array of . + /// + public byte[] BinaryBody { + get { + if (_binary == null) ReadResponseBody(); + return _binary!; + } + } + + #endregion + + #region Constructor + + private HttpResponse(IHttpRequest? request, HttpWebResponse response) { + Request = request; + Response = response; + Encoding = DetectResponseEncoding(); + } + + #endregion - // Convert the binary array into a raw text string - _body = Encoding.GetString(_binary); + #region Member methods + /// + /// Attemps to detect the encoding of the response body. The result is currently only based on the + /// Content-Type HTTP header. If an encoding can't be detected, UTF8 will be used as fallback. + /// + /// The of the response body. + private Encoding DetectResponseEncoding() { + + // Information in the header is seperated by ";" + foreach (string piece in ContentType.Split(';')) { + + // Search for the charset + Match regex = Regex.Match(piece.Trim().ToLowerInvariant(), "^charset=(.+?)$"); + + if (regex.Success) { + switch (regex.Groups[1].Value) { + case "us-ascii": return Encoding.ASCII; + case "iso-8859-1": + case "windows-1252": return Encoding.GetEncoding(1252); + case "utf-7": return Encoding.UTF7; + case "utf-8": return Encoding.UTF8; + case "utf-16": return Encoding.Unicode; + case "utf-32": return Encoding.UTF32; + } } } - #endregion + // Use UTF8 as fallback + return Encoding.UTF8; - #region Static methods + } - /// - /// Creates a new instance based on the specified . - /// - /// The instance of to be parsed. - /// A new instance of based on the specified . - [return: NotNullIfNotNull("response")] - public static HttpResponse? GetFromWebResponse(HttpWebResponse? response) { - return response == null ? null : new HttpResponse(null, response); - } + /// + /// Reads the response body from the response stream. The method will read the response body using an instance + /// of with a buffer size of 4096 bytes. + /// + private void ReadResponseBody() { + + // If "binary" isn't NULL, we have already read the response body + // once, and the stream is therefore already disposed + if (_binary != null) return; + + // Get a reference to the response stream (and dispose it once we're done) + using (Stream? stream = Response.GetResponseStream()) { + + // The stream really shouldn't be NULL, but just to be sure + if (stream == null) return; + + // Read the response stream into a binary array + using (BinaryReader reader = new(stream)) { + byte[] allBytes; + const int bufferSize = 4096; + using (var ms = new MemoryStream()) { + byte[] buffer = new byte[bufferSize]; + int count; + while ((count = reader.Read(buffer, 0, buffer.Length)) != 0) + ms.Write(buffer, 0, count); + allBytes = ms.ToArray(); + } + _binary = allBytes; + } - /// - /// Creates a new instance based on the specified . - /// - /// The instance of to be parsed. - /// The instance of that resulted in the response. - /// A new instance of based on the specified . - [return: NotNullIfNotNull("response")] - public static HttpResponse? GetFromWebResponse(HttpWebResponse? response, HttpRequest? request) { - return response == null ? null : new HttpResponse(request, response); - } + // Convert the binary array into a raw text string + _body = Encoding.GetString(_binary); - /// - /// Creates a new instance based on the specified . - /// - /// The instance of to be parsed. - /// The instance of that resulted in the response. - /// A new instance of based on the specified . - [return: NotNullIfNotNull("response")] - public static HttpResponse? GetFromWebResponse(HttpRequest? request, HttpWebResponse? response) { - return response == null ? null : new HttpResponse(request, response); } - #endregion + } + + #endregion + + #region Static methods + + /// + /// Creates a new instance based on the specified . + /// + /// The instance of to be parsed. + /// A new instance of based on the specified . + [return: NotNullIfNotNull("response")] + public static HttpResponse? GetFromWebResponse(HttpWebResponse? response) { + return response == null ? null : new HttpResponse(null, response); + } + + /// + /// Creates a new instance based on the specified . + /// + /// The instance of to be parsed. + /// The instance of that resulted in the response. + /// A new instance of based on the specified . + [return: NotNullIfNotNull("response")] + public static HttpResponse? GetFromWebResponse(HttpWebResponse? response, HttpRequest? request) { + return response == null ? null : new HttpResponse(request, response); + } + /// + /// Creates a new instance based on the specified . + /// + /// The instance of to be parsed. + /// The instance of that resulted in the response. + /// A new instance of based on the specified . + [return: NotNullIfNotNull("response")] + public static HttpResponse? GetFromWebResponse(HttpRequest? request, HttpWebResponse? response) { + return response == null ? null : new HttpResponse(request, response); } + #endregion + } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/HttpResponseBase.cs b/src/Skybrud.Essentials.Http/HttpResponseBase.cs index 01ee285..ffe9a4c 100644 --- a/src/Skybrud.Essentials.Http/HttpResponseBase.cs +++ b/src/Skybrud.Essentials.Http/HttpResponseBase.cs @@ -7,271 +7,269 @@ using Skybrud.Essentials.Xml; using System.Diagnostics.CodeAnalysis; -namespace Skybrud.Essentials.Http { +namespace Skybrud.Essentials.Http; + +/// +/// Class representing a response from a call to a server. Generally this class (or other classes inheriting from +/// this class) should be used to represent the object oriented (parsed) response wrapping an instance of +/// (raw response). +/// +public class HttpResponseBase { + + #region Properties + + /// + /// Gets a reference to the underlying raw response. + /// + public IHttpResponse Response { get; } + + /// + /// Gets the status code returned by the server. + /// + public HttpStatusCode StatusCode => Response.StatusCode; + + /// + /// Gets the status description returned by the server. + /// + public string StatusDescription => Response.StatusDescription; + + /// + /// Gets the HTTP method of the request to the server. + /// + public string Method => Response.Method; + + /// + /// Gets the content type of the response. + /// + public string ContentType => Response.ContentType; + + /// + /// Gets a collection of headers returned by the server. + /// + public IHttpHeaderCollection Headers => Response.Headers; + + /// + /// /// Gets the URI of the response (may differ from the requested URI - eg. if the request was redirected). + /// + public Uri ResponseUri => Response.ResponseUri; + + #endregion + + #region Constructors + + /// + /// Initializes a new instance based on the specified raw . + /// + /// The instance of representing the raw response. + protected HttpResponseBase(IHttpResponse response) { + Response = response; + } + + #endregion + + #region Member methods + + /// + /// Parses the specified string into an instance . + /// + /// The JSON string to be parsed. + /// An instance of parsed from the specified string. + protected static JToken ParseJsonToken(string json) { + return JsonUtils.ParseJsonToken(json); + } + + /// + /// Parses the specified string into an instance . + /// + /// The JSON string to be parsed. + /// An instance of parsed from the specified string. + protected static T ParseJsonToken(string json) { + return JsonUtils.ParseJsonToken(json); + } /// - /// Class representing a response from a call to a server. Generally this class (or other classes inheriting from - /// this class) should be used to represent the object oriented (parsed) response wrapping an instance of - /// (raw response). + /// Parses the specified string into an instance of . /// - public class HttpResponseBase { - - #region Properties - - /// - /// Gets a reference to the underlying raw response. - /// - public IHttpResponse Response { get; } - - /// - /// Gets the status code returned by the server. - /// - public HttpStatusCode StatusCode => Response.StatusCode; - - /// - /// Gets the status description returned by the server. - /// - public string StatusDescription => Response.StatusDescription; - - /// - /// Gets the HTTP method of the request to the server. - /// - public string Method => Response.Method; - - /// - /// Gets the content type of the response. - /// - public string ContentType => Response.ContentType; - - /// - /// Gets a collection of headers returned by the server. - /// - public IHttpHeaderCollection Headers => Response.Headers; - - /// - /// /// Gets the URI of the response (may differ from the requested URI - eg. if the request was redirected). - /// - public Uri ResponseUri => Response.ResponseUri; - - #endregion - - #region Constructors - - /// - /// Initializes a new instance based on the specified raw . - /// - /// The instance of representing the raw response. - protected HttpResponseBase(IHttpResponse response) { - Response = response; - } - - #endregion - - #region Member methods - - /// - /// Parses the specified string into an instance . - /// - /// The JSON string to be parsed. - /// An instance of parsed from the specified string. - protected static JToken ParseJsonToken(string json) { - return JsonUtils.ParseJsonToken(json); - } - - /// - /// Parses the specified string into an instance . - /// - /// The JSON string to be parsed. - /// An instance of parsed from the specified string. - protected static T ParseJsonToken(string json) { - return JsonUtils.ParseJsonToken(json); - } - - /// - /// Parses the specified string into an instance of . - /// - /// The type to be returned. - /// The JSON string to be parsed. - /// A callback function/method used for converting an instance of into - /// an instance of . - /// An instance of parsed from the specified string. - protected static T ParseJsonToken(string json, Func func) { - return JsonUtils.ParseJsonToken(json, func); - } - - /// - /// Parses the specified string into an instance of . - /// - /// The JSON string to be parsed. - /// An instance of parsed from the specified string. - protected static JObject ParseJsonObject(string json) { - return JsonUtils.ParseJsonObject(json); - } - - /// - /// Parses the specified string into an instance of . - /// - /// The type to be returned. - /// The JSON string to be parsed. - /// A callback function/method used for converting an instance of into an instance of . - /// An instance of parsed from the specified string. - protected static T ParseJsonObject(string json, Func func) { - return JsonUtils.ParseJsonObject(json, func); - } - - /// - /// Parses the specified string into an instance of . - /// - /// The JSON string to be parsed. - /// An instance of parsed from the specified string. - protected static JArray ParseJsonArray(string json) { - return JsonUtils.ParseJsonArray(json); - } - - /// - /// Parses the specified string into an array of . - /// - /// The JSON string to be parsed. - /// A callback function/method used for converting an instance of into an instance of . - /// An array of parsed from the specified string. - protected static T[] ParseJsonArray(string json, Func func) { - return JsonUtils.ParseJsonArray(json, func); - } - - /// - /// Attempts to parse the specified string into an instance of . - /// - /// The JSON string to parse. - /// When this method returns, holds the parsed if successful; otherwise, null. - /// true if the parsing was successful; otherwise, false. - protected static bool TryParseJsonToken(string json, [NotNullWhen(true)] out JToken? result) { - return JsonUtils.TryParseJsonToken(json, out result); - } - - /// - /// Attempts to parse the specified string into an instance of . - /// - /// The type of the output object. - /// The JSON string to parse. - /// When this method returns, holds the parsed if successful; otherwise, the default value of . - /// true if the parsing was successful; otherwise, false. - protected static bool TryParseJsonToken(string json, [NotNullWhen(true)] out T? result) { - return JsonUtils.TryParseJsonToken(json, out result); - } - - /// - /// Attempts to parse the specified string into an instance of . - /// - /// The type of the output object. - /// The JSON string to parse. - /// A callback function used for converting a into an instance of . - /// When this method returns, holds the parsed if successful; otherwise, the default value of . - /// true if the parsing was successful; otherwise, false. - protected static bool TryParseJsonToken(string json, Func callback, [NotNullWhen(true)] out T? result) { - return JsonUtils.TryParseJsonToken(json, callback, out result); - } - - /// - /// Attempts to parse the specified string into an instance of . - /// - /// The JSON string to parse. - /// When this method returns, holds the parsed if successful; otherwise, null. - /// true if the parsing was successful; otherwise, false. - protected static bool TryParseJsonObject(string json, [NotNullWhen(true)] out JObject? result) { - return JsonUtils.TryParseJsonObject(json, out result); - } - - /// - /// Attempts to parse the specified string into an instance of . - /// - /// The type of the output object. - /// The JSON string to parse. - /// When this method returns, holds the parsed if successful; otherwise, the default value of . - /// true if the parsing was successful; otherwise, false. - protected static bool TryParseJsonObject(string json, [NotNullWhen(true)] out T? result) { - return JsonUtils.TryParseJsonObject(json, out result); - } - - /// - /// Attempts to parse the specified string into an instance of . - /// - /// The type of the output object. - /// The JSON string to parse. - /// A callback function used for converting a into an instance of . - /// When this method returns, holds the parsed if successful; otherwise, the default value of . - /// true if the parsing was successful; otherwise, false. - protected static bool TryParseJsonObject(string json, Func callback, [NotNullWhen(true)] out T? result) { - return JsonUtils.TryParseJsonObject(json, callback, out result); - } - - /// - /// Attempts to parse the specified string into an instance of . - /// - /// The JSON string to parse. - /// When this method returns, holds the parsed if successful; otherwise, null. - /// true if the parsing was successful; otherwise, false. - protected static bool TryParseJsonArray(string json, [NotNullWhen(true)] out JArray? result) { - return JsonUtils.TryParseJsonArray(json, out result); - } - - /// - /// Attempts to parse the specified string into an instance of . - /// - /// The type of the output Array. - /// The JSON string to parse. - /// When this method returns, holds the parsed array of if successful; otherwise, null. - /// true if the parsing was successful; otherwise, false. - protected static bool TryParseJsonArray(string json, [NotNullWhen(true)] out T[]? result) { - return JsonUtils.TryParseJsonArray(json, out result); - } - - /// - /// Attempts to parse the specified string into an instance of . - /// - /// The type of the output array. - /// The JSON string to parse. - /// A callback function used for converting a into an instance of . - /// When this method returns, holds the parsed array of if successful; otherwise, null. - /// true if the parsing was successful; otherwise, false. - protected static bool TryParseJsonArray(string json, Func callback, [NotNullWhen(true)] out T[]? result) { - return JsonUtils.TryParseJsonArray(json, callback, out result); - } - - /// - /// Attempts to parse the specified string into an array of . - /// - /// The type of the output array. - /// The JSON string to parse. - /// A callback function used for converting the individual of the parsed array into instances of . - /// When this method returns, holds the parsed array of if successful; otherwise, null. - /// true if the parsing was successful; otherwise, false. - protected static bool TryParseJsonArray(string json, Func callback, [NotNullWhen(true)] out T[]? result) { - return JsonUtils.TryParseJsonArray(json, callback, out result); - } - - /// - /// Parses the specified into an instance of . - /// - /// The XML to be parsed. - /// An instance of . - protected static XElement ParseXmlElement(string xml) { - return XmlUtils.ParseXmlElement(xml); - } - - /// - /// Parses the specified into an instance of , which is then converted - /// into an instance of using the specified function. - /// - /// The type of the instance to be returned. - /// The XML to be parsed. - /// The callback function used for converting the parsed . - /// An instance of representing the specified . - protected static T ParseXmlElement(string xml, Func callback) { - return XmlUtils.ParseXmlElement(xml, callback); - } - - #endregion + /// The type to be returned. + /// The JSON string to be parsed. + /// A callback function/method used for converting an instance of into + /// an instance of . + /// An instance of parsed from the specified string. + protected static T ParseJsonToken(string json, Func func) { + return JsonUtils.ParseJsonToken(json, func); + } + /// + /// Parses the specified string into an instance of . + /// + /// The JSON string to be parsed. + /// An instance of parsed from the specified string. + protected static JObject ParseJsonObject(string json) { + return JsonUtils.ParseJsonObject(json); + } + + /// + /// Parses the specified string into an instance of . + /// + /// The type to be returned. + /// The JSON string to be parsed. + /// A callback function/method used for converting an instance of into an instance of . + /// An instance of parsed from the specified string. + protected static T ParseJsonObject(string json, Func func) { + return JsonUtils.ParseJsonObject(json, func); } + /// + /// Parses the specified string into an instance of . + /// + /// The JSON string to be parsed. + /// An instance of parsed from the specified string. + protected static JArray ParseJsonArray(string json) { + return JsonUtils.ParseJsonArray(json); + } + + /// + /// Parses the specified string into an array of . + /// + /// The JSON string to be parsed. + /// A callback function/method used for converting an instance of into an instance of . + /// An array of parsed from the specified string. + protected static T[] ParseJsonArray(string json, Func func) { + return JsonUtils.ParseJsonArray(json, func); + } + + /// + /// Attempts to parse the specified string into an instance of . + /// + /// The JSON string to parse. + /// When this method returns, holds the parsed if successful; otherwise, null. + /// true if the parsing was successful; otherwise, false. + protected static bool TryParseJsonToken(string json, [NotNullWhen(true)] out JToken? result) { + return JsonUtils.TryParseJsonToken(json, out result); + } + + /// + /// Attempts to parse the specified string into an instance of . + /// + /// The type of the output object. + /// The JSON string to parse. + /// When this method returns, holds the parsed if successful; otherwise, the default value of . + /// true if the parsing was successful; otherwise, false. + protected static bool TryParseJsonToken(string json, [NotNullWhen(true)] out T? result) { + return JsonUtils.TryParseJsonToken(json, out result); + } + + /// + /// Attempts to parse the specified string into an instance of . + /// + /// The type of the output object. + /// The JSON string to parse. + /// A callback function used for converting a into an instance of . + /// When this method returns, holds the parsed if successful; otherwise, the default value of . + /// true if the parsing was successful; otherwise, false. + protected static bool TryParseJsonToken(string json, Func callback, [NotNullWhen(true)] out T? result) { + return JsonUtils.TryParseJsonToken(json, callback, out result); + } + + /// + /// Attempts to parse the specified string into an instance of . + /// + /// The JSON string to parse. + /// When this method returns, holds the parsed if successful; otherwise, null. + /// true if the parsing was successful; otherwise, false. + protected static bool TryParseJsonObject(string json, [NotNullWhen(true)] out JObject? result) { + return JsonUtils.TryParseJsonObject(json, out result); + } + + /// + /// Attempts to parse the specified string into an instance of . + /// + /// The type of the output object. + /// The JSON string to parse. + /// When this method returns, holds the parsed if successful; otherwise, the default value of . + /// true if the parsing was successful; otherwise, false. + protected static bool TryParseJsonObject(string json, [NotNullWhen(true)] out T? result) { + return JsonUtils.TryParseJsonObject(json, out result); + } + + /// + /// Attempts to parse the specified string into an instance of . + /// + /// The type of the output object. + /// The JSON string to parse. + /// A callback function used for converting a into an instance of . + /// When this method returns, holds the parsed if successful; otherwise, the default value of . + /// true if the parsing was successful; otherwise, false. + protected static bool TryParseJsonObject(string json, Func callback, [NotNullWhen(true)] out T? result) { + return JsonUtils.TryParseJsonObject(json, callback, out result); + } + + /// + /// Attempts to parse the specified string into an instance of . + /// + /// The JSON string to parse. + /// When this method returns, holds the parsed if successful; otherwise, null. + /// true if the parsing was successful; otherwise, false. + protected static bool TryParseJsonArray(string json, [NotNullWhen(true)] out JArray? result) { + return JsonUtils.TryParseJsonArray(json, out result); + } + + /// + /// Attempts to parse the specified string into an instance of . + /// + /// The type of the output Array. + /// The JSON string to parse. + /// When this method returns, holds the parsed array of if successful; otherwise, null. + /// true if the parsing was successful; otherwise, false. + protected static bool TryParseJsonArray(string json, [NotNullWhen(true)] out T[]? result) { + return JsonUtils.TryParseJsonArray(json, out result); + } + + /// + /// Attempts to parse the specified string into an instance of . + /// + /// The type of the output array. + /// The JSON string to parse. + /// A callback function used for converting a into an instance of . + /// When this method returns, holds the parsed array of if successful; otherwise, null. + /// true if the parsing was successful; otherwise, false. + protected static bool TryParseJsonArray(string json, Func callback, [NotNullWhen(true)] out T[]? result) { + return JsonUtils.TryParseJsonArray(json, callback, out result); + } + + /// + /// Attempts to parse the specified string into an array of . + /// + /// The type of the output array. + /// The JSON string to parse. + /// A callback function used for converting the individual of the parsed array into instances of . + /// When this method returns, holds the parsed array of if successful; otherwise, null. + /// true if the parsing was successful; otherwise, false. + protected static bool TryParseJsonArray(string json, Func callback, [NotNullWhen(true)] out T[]? result) { + return JsonUtils.TryParseJsonArray(json, callback, out result); + } + + /// + /// Parses the specified into an instance of . + /// + /// The XML to be parsed. + /// An instance of . + protected static XElement ParseXmlElement(string xml) { + return XmlUtils.ParseXmlElement(xml); + } + + /// + /// Parses the specified into an instance of , which is then converted + /// into an instance of using the specified function. + /// + /// The type of the instance to be returned. + /// The XML to be parsed. + /// The callback function used for converting the parsed . + /// An instance of representing the specified . + protected static T ParseXmlElement(string xml, Func callback) { + return XmlUtils.ParseXmlElement(xml, callback); + } + + #endregion + } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/HttpResponseExtensions.cs b/src/Skybrud.Essentials.Http/HttpResponseExtensions.cs index 4aa3796..44da332 100644 --- a/src/Skybrud.Essentials.Http/HttpResponseExtensions.cs +++ b/src/Skybrud.Essentials.Http/HttpResponseExtensions.cs @@ -5,140 +5,138 @@ using System.Net; using System.Threading.Tasks; -namespace Skybrud.Essentials.Http { +namespace Skybrud.Essentials.Http; + +/// +/// Static class with various extension methods for . +/// +public static class HttpResponseExtensions { /// - /// Static class with various extension methods for . + /// Throws a exception if doesn't have a successful status code. /// - public static class HttpResponseExtensions { - - /// - /// Throws a exception if doesn't have a successful status code. - /// - /// The response. - /// - useful for method chaining. - /// If doesn't have a successful status code. - public static IHttpResponse ThrowIfNotSuccessful(this IHttpResponse response) { - if (response.StatusCode is HttpStatusCode.OK or HttpStatusCode.Created) return response; - throw new HttpException(response); - } - - /// - /// Throw a new exception if the response of doesn't have a successful status code. - /// - /// The task holding the response. - /// - useful for method chaining. - /// If the response of doesn't have a successful status code. - public static async Task ThrowIfNotSuccessful(this Task task) { - IHttpResponse response = await task; - if (response.StatusCode is HttpStatusCode.OK or HttpStatusCode.Created) return response; - throw new HttpException(response); - } + /// The response. + /// - useful for method chaining. + /// If doesn't have a successful status code. + public static IHttpResponse ThrowIfNotSuccessful(this IHttpResponse response) { + if (response.StatusCode is HttpStatusCode.OK or HttpStatusCode.Created) return response; + throw new HttpException(response); + } - /// - /// Deserializes the response body of the specified into an instance of . - /// - /// The response. - /// An instance of representing the deserialized value. - public static JToken AsJson(this IHttpResponse response) { - return JsonUtils.ParseJsonToken(response.Body); - } + /// + /// Throw a new exception if the response of doesn't have a successful status code. + /// + /// The task holding the response. + /// - useful for method chaining. + /// If the response of doesn't have a successful status code. + public static async Task ThrowIfNotSuccessful(this Task task) { + IHttpResponse response = await task; + if (response.StatusCode is HttpStatusCode.OK or HttpStatusCode.Created) return response; + throw new HttpException(response); + } - /// - /// Deserializes the response body of the specified into an instance of . - /// - /// The type to deserialize to. - /// The response. - /// An instance of representing the deserialized value. - public static T AsJson(this IHttpResponse response) { - return JsonUtils.ParseJsonToken(response.Body); - } + /// + /// Deserializes the response body of the specified into an instance of . + /// + /// The response. + /// An instance of representing the deserialized value. + public static JToken AsJson(this IHttpResponse response) { + return JsonUtils.ParseJsonToken(response.Body); + } - /// - /// Deserializes the response body of the specified into an instance of . - /// - /// The type to deserialize to. - /// The response. - /// A callback function used for converting the response body from to - /// An instance of representing the deserialized value. - public static T AsJson(this IHttpResponse response, Func callback) { - return callback(JsonUtils.ParseJsonToken(response.Body)); - } + /// + /// Deserializes the response body of the specified into an instance of . + /// + /// The type to deserialize to. + /// The response. + /// An instance of representing the deserialized value. + public static T AsJson(this IHttpResponse response) { + return JsonUtils.ParseJsonToken(response.Body); + } - /// - /// Deserializes the response body of the specified into an instance of . - /// - /// The type to deserialize to. - /// The response. - /// A callback function used for converting the response body from to - /// An instance of representing the deserialized value. - public static T AsJson(this IHttpResponse response, Func callback) { - return callback(JsonUtils.ParseJsonToken(response.Body)); - } + /// + /// Deserializes the response body of the specified into an instance of . + /// + /// The type to deserialize to. + /// The response. + /// A callback function used for converting the response body from to + /// An instance of representing the deserialized value. + public static T AsJson(this IHttpResponse response, Func callback) { + return callback(JsonUtils.ParseJsonToken(response.Body)); + } - /// - /// Deserializes the response body of the specified into an instance of . - /// - /// The response. - /// An instance of representing the deserialized value. - public static JArray AsJsonArray(this IHttpResponse response) { - return JsonUtils.ParseJsonArray(response.Body); - } + /// + /// Deserializes the response body of the specified into an instance of . + /// + /// The type to deserialize to. + /// The response. + /// A callback function used for converting the response body from to + /// An instance of representing the deserialized value. + public static T AsJson(this IHttpResponse response, Func callback) { + return callback(JsonUtils.ParseJsonToken(response.Body)); + } - /// - /// Deserializes the response body of the specified into an instance of . - /// - /// The type to deserialize to. - /// The response. - /// A callback function used for converting the response body from a array to an array of . - /// An array of representing the deserialized value. - public static T[] AsJsonArray(this IHttpResponse response, Func callback) { - return JsonUtils.ParseJsonArray(response.Body, callback); - } + /// + /// Deserializes the response body of the specified into an instance of . + /// + /// The response. + /// An instance of representing the deserialized value. + public static JArray AsJsonArray(this IHttpResponse response) { + return JsonUtils.ParseJsonArray(response.Body); + } - /// - /// Deserializes the response body of the response of the specified into an instance of . - /// - /// A task wrapping the response. - /// An instance of representing the deserialized value. - public static async Task AsJson(this Task task) { - IHttpResponse response = await task; - return JsonUtils.ParseJsonToken(response.Body); - } + /// + /// Deserializes the response body of the specified into an instance of . + /// + /// The type to deserialize to. + /// The response. + /// A callback function used for converting the response body from a array to an array of . + /// An array of representing the deserialized value. + public static T[] AsJsonArray(this IHttpResponse response, Func callback) { + return JsonUtils.ParseJsonArray(response.Body, callback); + } - /// - /// Deserializes the response body of the response of the specified into an instance of . - /// - /// The type to deserialize to. - /// A task wrapping the response. - /// An instance of representing the deserialized value. - public static async Task AsJson(this Task task) { - IHttpResponse response = await task; - return JsonUtils.ParseJsonToken(response.Body); - } + /// + /// Deserializes the response body of the response of the specified into an instance of . + /// + /// A task wrapping the response. + /// An instance of representing the deserialized value. + public static async Task AsJson(this Task task) { + IHttpResponse response = await task; + return JsonUtils.ParseJsonToken(response.Body); + } - /// - /// Deserializes the response body of the response of the specified into an instance of . - /// - /// A task wrapping the response. - /// An instance of representing the deserialized value. - public static async Task AsJsonArray(this Task task) { - IHttpResponse response = await task; - return JsonUtils.ParseJsonArray(response.Body); - } + /// + /// Deserializes the response body of the response of the specified into an instance of . + /// + /// The type to deserialize to. + /// A task wrapping the response. + /// An instance of representing the deserialized value. + public static async Task AsJson(this Task task) { + IHttpResponse response = await task; + return JsonUtils.ParseJsonToken(response.Body); + } - /// - /// Deserializes the response body of the response of the specified into an array of . - /// - /// The type to deserialize to. - /// A task wrapping the response. - /// A callback function used for converting the response body from to . - /// An array of representing the deserialized value. - public static async Task AsJsonArray(this Task task, Func callback) { - IHttpResponse response = await task; - return JsonUtils.ParseJsonArray(response.Body, callback); - } + /// + /// Deserializes the response body of the response of the specified into an instance of . + /// + /// A task wrapping the response. + /// An instance of representing the deserialized value. + public static async Task AsJsonArray(this Task task) { + IHttpResponse response = await task; + return JsonUtils.ParseJsonArray(response.Body); + } + /// + /// Deserializes the response body of the response of the specified into an array of . + /// + /// The type to deserialize to. + /// A task wrapping the response. + /// A callback function used for converting the response body from to . + /// An array of representing the deserialized value. + public static async Task AsJsonArray(this Task task, Func callback) { + IHttpResponse response = await task; + return JsonUtils.ParseJsonArray(response.Body, callback); } } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/HttpUtils.Http.cs b/src/Skybrud.Essentials.Http/HttpUtils.Http.cs index e4e9fd1..1dfafb7 100644 --- a/src/Skybrud.Essentials.Http/HttpUtils.Http.cs +++ b/src/Skybrud.Essentials.Http/HttpUtils.Http.cs @@ -2,366 +2,364 @@ using Skybrud.Essentials.Http.Collections; using Skybrud.Essentials.Http.Options; -namespace Skybrud.Essentials.Http { +namespace Skybrud.Essentials.Http; - public static partial class HttpUtils { +public static partial class HttpUtils { + + /// + /// Static class with utility methods related to HTTP requests and responses. + /// + [Obsolete("use Requests class instead.")] + public static partial class Http { + + #region DoHttpGetRequest + + /// + /// Makes a HTTP GET request to the specified . + /// + /// The URL of the request. + /// An instance of representing the response. + public static IHttpResponse DoHttpGetRequest(string url) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return DoHttpRequest(HttpMethod.Get, url, default(IHttpQueryString)); + } + + /// + /// Makes a GET request to the specified . + /// + /// The URL of the request. + /// The options for the call to the specified . + /// An instance of representing the response. + public static IHttpResponse DoHttpGetRequest(string url, IHttpGetOptions options) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + if (options == null) throw new ArgumentNullException(nameof(options)); + return DoHttpRequest(HttpMethod.Get, url, options.GetQueryString()); + } + + /// + /// Makes a GET request to the specified . + /// + /// The URL of the request. + /// The query string of the request. + /// An instance of representing the response. + public static IHttpResponse DoHttpGetRequest(string url, IHttpQueryString queryString) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return DoHttpRequest(HttpMethod.Get, url, queryString); + } + + #endregion + + #region DoHttpPostRequest /// - /// Static class with utility methods related to HTTP requests and responses. + /// Makes a POST request to the specified . /// - [Obsolete("use Requests class instead.")] - public static partial class Http { - - #region DoHttpGetRequest - - /// - /// Makes a HTTP GET request to the specified . - /// - /// The URL of the request. - /// An instance of representing the response. - public static IHttpResponse DoHttpGetRequest(string url) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return DoHttpRequest(HttpMethod.Get, url, default(IHttpQueryString)); - } - - /// - /// Makes a GET request to the specified . - /// - /// The URL of the request. - /// The options for the call to the specified . - /// An instance of representing the response. - public static IHttpResponse DoHttpGetRequest(string url, IHttpGetOptions options) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - if (options == null) throw new ArgumentNullException(nameof(options)); - return DoHttpRequest(HttpMethod.Get, url, options.GetQueryString()); - } - - /// - /// Makes a GET request to the specified . - /// - /// The URL of the request. - /// The query string of the request. - /// An instance of representing the response. - public static IHttpResponse DoHttpGetRequest(string url, IHttpQueryString queryString) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return DoHttpRequest(HttpMethod.Get, url, queryString); - } - - #endregion - - #region DoHttpPostRequest - - /// - /// Makes a POST request to the specified . - /// - /// The URL of the request. - /// An instance of representing the response. - public static IHttpResponse DoHttpPostRequest(string url) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return DoHttpRequest(HttpMethod.Post, url, default(IHttpQueryString), default(IHttpPostData)); - } - - /// - /// Makes a POST request to the specified . - /// - /// The URL of the request. - /// The options for the call to the specified . - /// An instance of representing the response. - public static IHttpResponse DoHttpPostRequest(string url, IHttpGetOptions? options) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return DoHttpRequest(HttpMethod.Post, url, options?.GetQueryString(), null); - } - - /// - /// Makes a POST request to the specified . - /// - /// The URL of the request. - /// The options for the call to the specified . - /// An instance of representing the response. - public static IHttpResponse DoHttpPostRequest(string url, IHttpPostOptions? options) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return DoHttpRequest(HttpMethod.Post, url, options?.GetQueryString(), options?.GetPostData()); - } - - /// - /// Makes a POST request to the specified . - /// - /// The base URL of the request (no query string). - /// The query string. - /// An instance of representing the raw response. - public static IHttpResponse DoHttpPostRequest(string url, IHttpQueryString? queryString) { - return DoHttpRequest(HttpMethod.Post, url, queryString, null); - } - - /// - /// Makes a POST request to the specified . - /// - /// The base URL of the request (no query string). - /// The POST data. - /// An instance of representing the raw response. - public static IHttpResponse DoHttpPostRequest(string url, IHttpPostData? postData) { - return DoHttpRequest(HttpMethod.Post, url, null, postData); - } - - /// - /// Makes a POST request to the specified . - /// - /// The URL of the request. - /// The query string of the request. - /// The POST data of the request. - /// An instance of representing the response. - public static IHttpResponse DoHttpPostRequest(string url, IHttpQueryString? queryString, IHttpPostData? postData) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return DoHttpRequest(HttpMethod.Post, url, queryString, postData); - } - - #endregion - - #region DoHttpPutRequest - - /// - /// Makes a PUT request to the specified . - /// - /// The URL of the request. - /// An instance of representing the response. - public static IHttpResponse DoHttpPutRequest(string url) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return DoHttpRequest(HttpMethod.Put, url, default(IHttpQueryString), default(IHttpPostData)); - } - - /// - /// Makes a PUT request to the specified . - /// - /// The URL of the request. - /// The options for the call to the specified . - /// An instance of representing the response. - public static IHttpResponse DoHttpPutRequest(string url, IHttpGetOptions? options) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return DoHttpRequest(HttpMethod.Put, url, options?.GetQueryString(), null); - } - - /// - /// Makes a PUT request to the specified . - /// - /// The URL of the request. - /// The options for the call to the specified . - /// An instance of representing the response. - public static IHttpResponse DoHttpPutRequest(string url, IHttpPostOptions? options) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return DoHttpRequest(HttpMethod.Put, url, options?.GetQueryString(), options?.GetPostData()); - } - - /// - /// Makes a PUT request to the specified . - /// - /// The base URL of the request (no query string). - /// The query string. - /// An instance of representing the raw response. - public static IHttpResponse DoHttpPutRequest(string url, IHttpQueryString? queryString) { - return DoHttpRequest(HttpMethod.Put, url, queryString, null); - } - - /// - /// Makes a PUT request to the specified . - /// - /// The base URL of the request (no query string). - /// The PUT data. - /// An instance of representing the raw response. - public static IHttpResponse DoHttpPutRequest(string url, IHttpPostData? postData) { - return DoHttpRequest(HttpMethod.Put, url, null, postData); - } - - /// - /// Makes a PUT request to the specified . - /// - /// The URL of the request. - /// The query string of the request. - /// The PUT data of the request. - /// An instance of representing the response. - public static IHttpResponse DoHttpPutRequest(string url, IHttpQueryString? queryString, IHttpPostData? postData) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return DoHttpRequest(HttpMethod.Put, url, queryString, postData); - } - - #endregion - - #region DoHttpPatchRequest - - /// - /// Makes a PATCH request to the specified . - /// - /// The URL of the request. - /// An instance of representing the response. - public static IHttpResponse DoHttpPatchRequest(string url) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return DoHttpRequest(HttpMethod.Patch, url, default(IHttpQueryString), default(IHttpPostData)); - } - - /// - /// Makes a PATCH request to the specified . - /// - /// The URL of the request. - /// The options for the call to the specified . - /// An instance of representing the response. - public static IHttpResponse DoHttpPatchRequest(string url, IHttpGetOptions? options) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return DoHttpRequest(HttpMethod.Patch, url, options?.GetQueryString(), null); - } - - /// - /// Makes a PATCH request to the specified . - /// - /// The URL of the request. - /// The options for the call to the specified . - /// An instance of representing the response. - public static IHttpResponse DoHttpPatchRequest(string url, IHttpPostOptions? options) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return DoHttpRequest(HttpMethod.Patch, url, options?.GetQueryString(), options?.GetPostData()); - } - - /// - /// Makes a PATCH request to the specified . - /// - /// The base URL of the request (no query string). - /// The query string. - /// An instance of representing the raw response. - public static IHttpResponse DoHttpPatchRequest(string url, IHttpQueryString? queryString) { - return DoHttpRequest(HttpMethod.Patch, url, queryString, null); - } - - /// - /// Makes a PATCH request to the specified . - /// - /// The base URL of the request (no query string). - /// The PATCH data. - /// An instance of representing the raw response. - public static IHttpResponse DoHttpPatchRequest(string url, IHttpPostData? postData) { - return DoHttpRequest(HttpMethod.Patch, url, null, postData); - } - - /// - /// Makes a PATCH request to the specified . - /// - /// The URL of the request. - /// The query string of the request. - /// The PATCH data of the request. - /// An instance of representing the response. - public static IHttpResponse DoHttpPatchRequest(string url, IHttpQueryString? queryString, IHttpPostData? postData) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return DoHttpRequest(HttpMethod.Patch, url, queryString, postData); - } - - #endregion - - #region DoHttpDeleteRequest - - /// - /// Makes a HTTP DELETE request to the specified . - /// - /// The URL of the request. - /// An instance of representing the response. - public static IHttpResponse DoHttpDeleteRequest(string url) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return DoHttpRequest(HttpMethod.Delete, url, default(IHttpQueryString)); - } - - /// - /// Makes a DELETE request to the specified . - /// - /// The URL of the request. - /// The options for the call to the specified . - /// An instance of representing the response. - public static IHttpResponse DoHttpDeleteRequest(string url, IHttpGetOptions? options) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return DoHttpRequest(HttpMethod.Delete, url, options?.GetQueryString()); - } - - /// - /// Makes a DELETE request to the specified . - /// - /// The URL of the request. - /// The query string of the request. - /// An instance of representing the response. - public static IHttpResponse DoHttpDeleteRequest(string url, IHttpQueryString? queryString) { - if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - return DoHttpRequest(HttpMethod.Delete, url, queryString); - } - - #endregion - - #region DoHttpRequest - - /// - /// Makes a HTTP request to the underlying API based on the specified parameters. - /// - /// The HTTP method of the request. - /// The base URL of the request (no query string). - /// An instance of representing the raw response. - public static IHttpResponse DoHttpRequest(HttpMethod method, string url) { - return DoHttpRequest(method, url, default(IHttpQueryString), default(IHttpPostData)); - } - - /// - /// Makes a HTTP request to the underlying API based on the specified parameters. - /// - /// The HTTP method of the request. - /// The base URL of the request (no query string). - /// The options for the call to the API. - /// An instance of representing the raw response. - public static IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpGetOptions? options) { - IHttpQueryString? queryString = options?.GetQueryString(); - return DoHttpRequest(method, url, queryString); - } - - /// - /// Makes a HTTP request to the underlying API based on the specified parameters. - /// - /// The HTTP method of the request. - /// The base URL of the request (no query string). - /// The query string. - /// An instance of representing the raw response. - public static IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpQueryString? queryString) { - return DoHttpRequest(method, url, queryString, null); - } - - /// - /// Makes a HTTP request to the underlying API based on the specified parameters. - /// - /// The HTTP method of the request. - /// The base URL of the request (no query string). - /// The POST data. - /// An instance of representing the raw response. - public static IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpPostData? postData) { - return DoHttpRequest(method, url, null, postData); - } - - /// - /// Makes a HTTP request using the specified and . - /// - /// The URL of the request. - /// The HTTP method of the request. - /// The query string of the request. - /// The POST data of the request. - /// An instance of representing the response. - private static IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpQueryString? queryString, IHttpPostData? postData) { - - // Initialize the request - HttpRequest request = new() { - Url = url, - Method = method, - QueryString = queryString!, - PostData = postData! - }; - - // Make the call to the URL - return request.GetResponse(); - - } - - #endregion + /// The URL of the request. + /// An instance of representing the response. + public static IHttpResponse DoHttpPostRequest(string url) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return DoHttpRequest(HttpMethod.Post, url, default(IHttpQueryString), default(IHttpPostData)); + } + + /// + /// Makes a POST request to the specified . + /// + /// The URL of the request. + /// The options for the call to the specified . + /// An instance of representing the response. + public static IHttpResponse DoHttpPostRequest(string url, IHttpGetOptions? options) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return DoHttpRequest(HttpMethod.Post, url, options?.GetQueryString(), null); + } + + /// + /// Makes a POST request to the specified . + /// + /// The URL of the request. + /// The options for the call to the specified . + /// An instance of representing the response. + public static IHttpResponse DoHttpPostRequest(string url, IHttpPostOptions? options) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return DoHttpRequest(HttpMethod.Post, url, options?.GetQueryString(), options?.GetPostData()); + } + + /// + /// Makes a POST request to the specified . + /// + /// The base URL of the request (no query string). + /// The query string. + /// An instance of representing the raw response. + public static IHttpResponse DoHttpPostRequest(string url, IHttpQueryString? queryString) { + return DoHttpRequest(HttpMethod.Post, url, queryString, null); + } + /// + /// Makes a POST request to the specified . + /// + /// The base URL of the request (no query string). + /// The POST data. + /// An instance of representing the raw response. + public static IHttpResponse DoHttpPostRequest(string url, IHttpPostData? postData) { + return DoHttpRequest(HttpMethod.Post, url, null, postData); } + /// + /// Makes a POST request to the specified . + /// + /// The URL of the request. + /// The query string of the request. + /// The POST data of the request. + /// An instance of representing the response. + public static IHttpResponse DoHttpPostRequest(string url, IHttpQueryString? queryString, IHttpPostData? postData) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return DoHttpRequest(HttpMethod.Post, url, queryString, postData); + } + + #endregion + + #region DoHttpPutRequest + + /// + /// Makes a PUT request to the specified . + /// + /// The URL of the request. + /// An instance of representing the response. + public static IHttpResponse DoHttpPutRequest(string url) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return DoHttpRequest(HttpMethod.Put, url, default(IHttpQueryString), default(IHttpPostData)); + } + + /// + /// Makes a PUT request to the specified . + /// + /// The URL of the request. + /// The options for the call to the specified . + /// An instance of representing the response. + public static IHttpResponse DoHttpPutRequest(string url, IHttpGetOptions? options) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return DoHttpRequest(HttpMethod.Put, url, options?.GetQueryString(), null); + } + + /// + /// Makes a PUT request to the specified . + /// + /// The URL of the request. + /// The options for the call to the specified . + /// An instance of representing the response. + public static IHttpResponse DoHttpPutRequest(string url, IHttpPostOptions? options) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return DoHttpRequest(HttpMethod.Put, url, options?.GetQueryString(), options?.GetPostData()); + } + + /// + /// Makes a PUT request to the specified . + /// + /// The base URL of the request (no query string). + /// The query string. + /// An instance of representing the raw response. + public static IHttpResponse DoHttpPutRequest(string url, IHttpQueryString? queryString) { + return DoHttpRequest(HttpMethod.Put, url, queryString, null); + } + + /// + /// Makes a PUT request to the specified . + /// + /// The base URL of the request (no query string). + /// The PUT data. + /// An instance of representing the raw response. + public static IHttpResponse DoHttpPutRequest(string url, IHttpPostData? postData) { + return DoHttpRequest(HttpMethod.Put, url, null, postData); + } + + /// + /// Makes a PUT request to the specified . + /// + /// The URL of the request. + /// The query string of the request. + /// The PUT data of the request. + /// An instance of representing the response. + public static IHttpResponse DoHttpPutRequest(string url, IHttpQueryString? queryString, IHttpPostData? postData) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return DoHttpRequest(HttpMethod.Put, url, queryString, postData); + } + + #endregion + + #region DoHttpPatchRequest + + /// + /// Makes a PATCH request to the specified . + /// + /// The URL of the request. + /// An instance of representing the response. + public static IHttpResponse DoHttpPatchRequest(string url) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return DoHttpRequest(HttpMethod.Patch, url, default(IHttpQueryString), default(IHttpPostData)); + } + + /// + /// Makes a PATCH request to the specified . + /// + /// The URL of the request. + /// The options for the call to the specified . + /// An instance of representing the response. + public static IHttpResponse DoHttpPatchRequest(string url, IHttpGetOptions? options) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return DoHttpRequest(HttpMethod.Patch, url, options?.GetQueryString(), null); + } + + /// + /// Makes a PATCH request to the specified . + /// + /// The URL of the request. + /// The options for the call to the specified . + /// An instance of representing the response. + public static IHttpResponse DoHttpPatchRequest(string url, IHttpPostOptions? options) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return DoHttpRequest(HttpMethod.Patch, url, options?.GetQueryString(), options?.GetPostData()); + } + + /// + /// Makes a PATCH request to the specified . + /// + /// The base URL of the request (no query string). + /// The query string. + /// An instance of representing the raw response. + public static IHttpResponse DoHttpPatchRequest(string url, IHttpQueryString? queryString) { + return DoHttpRequest(HttpMethod.Patch, url, queryString, null); + } + + /// + /// Makes a PATCH request to the specified . + /// + /// The base URL of the request (no query string). + /// The PATCH data. + /// An instance of representing the raw response. + public static IHttpResponse DoHttpPatchRequest(string url, IHttpPostData? postData) { + return DoHttpRequest(HttpMethod.Patch, url, null, postData); + } + + /// + /// Makes a PATCH request to the specified . + /// + /// The URL of the request. + /// The query string of the request. + /// The PATCH data of the request. + /// An instance of representing the response. + public static IHttpResponse DoHttpPatchRequest(string url, IHttpQueryString? queryString, IHttpPostData? postData) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return DoHttpRequest(HttpMethod.Patch, url, queryString, postData); + } + + #endregion + + #region DoHttpDeleteRequest + + /// + /// Makes a HTTP DELETE request to the specified . + /// + /// The URL of the request. + /// An instance of representing the response. + public static IHttpResponse DoHttpDeleteRequest(string url) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return DoHttpRequest(HttpMethod.Delete, url, default(IHttpQueryString)); + } + + /// + /// Makes a DELETE request to the specified . + /// + /// The URL of the request. + /// The options for the call to the specified . + /// An instance of representing the response. + public static IHttpResponse DoHttpDeleteRequest(string url, IHttpGetOptions? options) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return DoHttpRequest(HttpMethod.Delete, url, options?.GetQueryString()); + } + + /// + /// Makes a DELETE request to the specified . + /// + /// The URL of the request. + /// The query string of the request. + /// An instance of representing the response. + public static IHttpResponse DoHttpDeleteRequest(string url, IHttpQueryString? queryString) { + if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + return DoHttpRequest(HttpMethod.Delete, url, queryString); + } + + #endregion + + #region DoHttpRequest + + /// + /// Makes a HTTP request to the underlying API based on the specified parameters. + /// + /// The HTTP method of the request. + /// The base URL of the request (no query string). + /// An instance of representing the raw response. + public static IHttpResponse DoHttpRequest(HttpMethod method, string url) { + return DoHttpRequest(method, url, default(IHttpQueryString), default(IHttpPostData)); + } + + /// + /// Makes a HTTP request to the underlying API based on the specified parameters. + /// + /// The HTTP method of the request. + /// The base URL of the request (no query string). + /// The options for the call to the API. + /// An instance of representing the raw response. + public static IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpGetOptions? options) { + IHttpQueryString? queryString = options?.GetQueryString(); + return DoHttpRequest(method, url, queryString); + } + + /// + /// Makes a HTTP request to the underlying API based on the specified parameters. + /// + /// The HTTP method of the request. + /// The base URL of the request (no query string). + /// The query string. + /// An instance of representing the raw response. + public static IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpQueryString? queryString) { + return DoHttpRequest(method, url, queryString, null); + } + + /// + /// Makes a HTTP request to the underlying API based on the specified parameters. + /// + /// The HTTP method of the request. + /// The base URL of the request (no query string). + /// The POST data. + /// An instance of representing the raw response. + public static IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpPostData? postData) { + return DoHttpRequest(method, url, null, postData); + } + + /// + /// Makes a HTTP request using the specified and . + /// + /// The URL of the request. + /// The HTTP method of the request. + /// The query string of the request. + /// The POST data of the request. + /// An instance of representing the response. + private static IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpQueryString? queryString, IHttpPostData? postData) { + + // Initialize the request + HttpRequest request = new() { + Url = url, + Method = method, + QueryString = queryString!, + PostData = postData! + }; + + // Make the call to the URL + return request.GetResponse(); + + } + + #endregion + } } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/HttpUtils.Requests.cs b/src/Skybrud.Essentials.Http/HttpUtils.Requests.cs index 7826187..e0f8b1e 100644 --- a/src/Skybrud.Essentials.Http/HttpUtils.Requests.cs +++ b/src/Skybrud.Essentials.Http/HttpUtils.Requests.cs @@ -3,320 +3,318 @@ using Skybrud.Essentials.Http.Collections; using Skybrud.Essentials.Http.Options; -namespace Skybrud.Essentials.Http { +namespace Skybrud.Essentials.Http; - public static partial class HttpUtils { +public static partial class HttpUtils { + + /// + /// Static class with utility methods related to making HTTP requests. + /// + public static partial class Requests { + + #region Get + + /// + /// Makes a HTTP GET request to the specified . + /// + /// The URL of the request. + /// An instance of representing the response. + public static IHttpResponse Get(string url) { + return HttpRequest.Get(url).GetResponse(); + } + + /// + /// Makes a GET request to the specified . + /// + /// The URL of the request. + /// The options for the call to the specified . + /// An instance of representing the response. + [Obsolete("Use 'GetResponse' method and 'IHttpRequestOptions' class as parameter instead.")] + public static IHttpResponse Get(string url, IHttpGetOptions? options) { + return HttpRequest.Get(url, options?.GetQueryString()).GetResponse(); + } + + /// + /// Makes a GET request to the specified . + /// + /// The URL of the request. + /// The query string of the request. + /// An instance of representing the response. + public static IHttpResponse Get(string url, IHttpQueryString? queryString) { + return HttpRequest.Get(url, queryString).GetResponse(); + } + + #endregion + + #region Post + + /// + /// Makes a POST request to the specified . + /// + /// The URL of the request. + /// An instance of representing the response. + public static IHttpResponse Post(string url) { + return HttpRequest.Post(url).GetResponse(); + } + + /// + /// Makes a POST request to the specified . + /// + /// The URL of the request. + /// The options for the call to the specified . + /// An instance of representing the response. + [Obsolete("Use 'GetResponse' method and 'IHttpRequestOptions' class as parameter instead.")] + public static IHttpResponse Post(string url, IHttpGetOptions? options) { + return HttpRequest.Post(url, options?.GetQueryString()).GetResponse(); + } + + /// + /// Makes a POST request to the specified . + /// + /// The URL of the request. + /// The options for the call to the specified . + /// An instance of representing the response. + [Obsolete("Use 'GetResponse' method and 'IHttpRequestOptions' class as parameter instead.")] + public static IHttpResponse Post(string url, IHttpPostOptions? options) { + return HttpRequest.Post(url, options?.GetQueryString(), options?.GetPostData()).GetResponse(); + } + + /// + /// Makes a POST request to the specified . + /// + /// The base URL of the request (no query string). + /// The query string. + /// An instance of representing the raw response. + public static IHttpResponse Post(string url, IHttpQueryString? queryString) { + return HttpRequest.Post(url, queryString).GetResponse(); + } + + /// + /// Makes a POST request to the specified . + /// + /// The base URL of the request (no query string). + /// The POST data. + /// An instance of representing the raw response. + public static IHttpResponse Post(string url, IHttpPostData? postData) { + return HttpRequest.Post(url, postData).GetResponse(); + } + + /// + /// Makes a POST request to the specified . + /// + /// The URL of the request. + /// The query string of the request. + /// The POST data of the request. + /// An instance of representing the response. + public static IHttpResponse Post(string url, IHttpQueryString queryString, IHttpPostData postData) { + return HttpRequest.Post(url, queryString, postData).GetResponse(); + } + + /// + /// Makes a POST request to the specified and JSON . + /// + /// The URL of the request. + /// The representing the POST body. + /// An instance of representing the response. + public static IHttpResponse Post(string url, JToken body) { + return HttpRequest.Post(url, body).GetResponse(); + } + + /// + /// Makes a POST request to the specified and JSON . + /// + /// The URL of the request. + /// The query string of the request. + /// The representing the POST body. + /// An instance of representing the response. + public static IHttpResponse Post(string url, IHttpQueryString? queryString, JToken body) { + return HttpRequest.Post(url, queryString, body).GetResponse(); + } + + #endregion + + #region Put + + /// + /// Makes a PUT request to the specified . + /// + /// The URL of the request. + /// An instance of representing the response. + public static IHttpResponse Put(string url) { + return HttpRequest.Put(url).GetResponse(); + } + + /// + /// Makes a PUT request to the specified . + /// + /// The URL of the request. + /// The options for the call to the specified . + /// An instance of representing the response. + [Obsolete("Use 'GetResponse' method and 'IHttpRequestOptions' class as parameter instead.")] + public static IHttpResponse Put(string url, IHttpGetOptions? options) { + return HttpRequest.Put(url, options?.GetQueryString()).GetResponse(); + } /// - /// Static class with utility methods related to making HTTP requests. + /// Makes a PUT request to the specified . /// - public static partial class Requests { - - #region Get - - /// - /// Makes a HTTP GET request to the specified . - /// - /// The URL of the request. - /// An instance of representing the response. - public static IHttpResponse Get(string url) { - return HttpRequest.Get(url).GetResponse(); - } - - /// - /// Makes a GET request to the specified . - /// - /// The URL of the request. - /// The options for the call to the specified . - /// An instance of representing the response. - [Obsolete("Use 'GetResponse' method and 'IHttpRequestOptions' class as parameter instead.")] - public static IHttpResponse Get(string url, IHttpGetOptions? options) { - return HttpRequest.Get(url, options?.GetQueryString()).GetResponse(); - } - - /// - /// Makes a GET request to the specified . - /// - /// The URL of the request. - /// The query string of the request. - /// An instance of representing the response. - public static IHttpResponse Get(string url, IHttpQueryString? queryString) { - return HttpRequest.Get(url, queryString).GetResponse(); - } - - #endregion - - #region Post - - /// - /// Makes a POST request to the specified . - /// - /// The URL of the request. - /// An instance of representing the response. - public static IHttpResponse Post(string url) { - return HttpRequest.Post(url).GetResponse(); - } - - /// - /// Makes a POST request to the specified . - /// - /// The URL of the request. - /// The options for the call to the specified . - /// An instance of representing the response. - [Obsolete("Use 'GetResponse' method and 'IHttpRequestOptions' class as parameter instead.")] - public static IHttpResponse Post(string url, IHttpGetOptions? options) { - return HttpRequest.Post(url, options?.GetQueryString()).GetResponse(); - } - - /// - /// Makes a POST request to the specified . - /// - /// The URL of the request. - /// The options for the call to the specified . - /// An instance of representing the response. - [Obsolete("Use 'GetResponse' method and 'IHttpRequestOptions' class as parameter instead.")] - public static IHttpResponse Post(string url, IHttpPostOptions? options) { - return HttpRequest.Post(url, options?.GetQueryString(), options?.GetPostData()).GetResponse(); - } - - /// - /// Makes a POST request to the specified . - /// - /// The base URL of the request (no query string). - /// The query string. - /// An instance of representing the raw response. - public static IHttpResponse Post(string url, IHttpQueryString? queryString) { - return HttpRequest.Post(url, queryString).GetResponse(); - } - - /// - /// Makes a POST request to the specified . - /// - /// The base URL of the request (no query string). - /// The POST data. - /// An instance of representing the raw response. - public static IHttpResponse Post(string url, IHttpPostData? postData) { - return HttpRequest.Post(url, postData).GetResponse(); - } - - /// - /// Makes a POST request to the specified . - /// - /// The URL of the request. - /// The query string of the request. - /// The POST data of the request. - /// An instance of representing the response. - public static IHttpResponse Post(string url, IHttpQueryString queryString, IHttpPostData postData) { - return HttpRequest.Post(url, queryString, postData).GetResponse(); - } - - /// - /// Makes a POST request to the specified and JSON . - /// - /// The URL of the request. - /// The representing the POST body. - /// An instance of representing the response. - public static IHttpResponse Post(string url, JToken body) { - return HttpRequest.Post(url, body).GetResponse(); - } - - /// - /// Makes a POST request to the specified and JSON . - /// - /// The URL of the request. - /// The query string of the request. - /// The representing the POST body. - /// An instance of representing the response. - public static IHttpResponse Post(string url, IHttpQueryString? queryString, JToken body) { - return HttpRequest.Post(url, queryString, body).GetResponse(); - } - - #endregion - - #region Put - - /// - /// Makes a PUT request to the specified . - /// - /// The URL of the request. - /// An instance of representing the response. - public static IHttpResponse Put(string url) { - return HttpRequest.Put(url).GetResponse(); - } - - /// - /// Makes a PUT request to the specified . - /// - /// The URL of the request. - /// The options for the call to the specified . - /// An instance of representing the response. - [Obsolete("Use 'GetResponse' method and 'IHttpRequestOptions' class as parameter instead.")] - public static IHttpResponse Put(string url, IHttpGetOptions? options) { - return HttpRequest.Put(url, options?.GetQueryString()).GetResponse(); - } - - /// - /// Makes a PUT request to the specified . - /// - /// The URL of the request. - /// The options for the call to the specified . - /// An instance of representing the response. - [Obsolete("Use 'GetResponse' method and 'IHttpRequestOptions' class as parameter instead.")] - public static IHttpResponse Put(string url, IHttpPostOptions? options) { - return HttpRequest.Put(url, options?.GetQueryString(), options?.GetPostData()).GetResponse(); - } - - /// - /// Makes a PUT request to the specified . - /// - /// The base URL of the request (no query string). - /// The query string. - /// An instance of representing the raw response. - public static IHttpResponse Put(string url, IHttpQueryString? queryString) { - return HttpRequest.Put(url, queryString).GetResponse(); - } - - /// - /// Makes a PUT request to the specified . - /// - /// The base URL of the request (no query string). - /// The PUT data. - /// An instance of representing the raw response. - public static IHttpResponse Put(string url, IHttpPostData? postData) { - return HttpRequest.Put(url, postData).GetResponse(); - } - - /// - /// Makes a PUT request to the specified . - /// - /// The URL of the request. - /// The query string of the request. - /// The PUT data of the request. - /// An instance of representing the response. - public static IHttpResponse Put(string url, IHttpQueryString? queryString, IHttpPostData? postData) { - return HttpRequest.Put(url, queryString, postData).GetResponse(); - } - - #endregion - - #region Patch - - /// - /// Makes a PATCH request to the specified . - /// - /// The URL of the request. - /// An instance of representing the response. - public static IHttpResponse Patch(string url) { - return HttpRequest.Patch(url).GetResponse(); - } - - /// - /// Makes a PATCH request to the specified . - /// - /// The URL of the request. - /// The options for the call to the specified . - /// An instance of representing the response. - [Obsolete("Use 'GetResponse' method and 'IHttpRequestOptions' class as parameter instead.")] - public static IHttpResponse Patch(string url, IHttpGetOptions? options) { - return HttpRequest.Patch(url, options?.GetQueryString()).GetResponse(); - } - - /// - /// Makes a PATCH request to the specified . - /// - /// The URL of the request. - /// The options for the call to the specified . - /// An instance of representing the response. - [Obsolete("Use 'GetResponse' method and 'IHttpRequestOptions' class as parameter instead.")] - public static IHttpResponse Patch(string url, IHttpPostOptions? options) { - return HttpRequest.Patch(url, options?.GetQueryString(), options?.GetPostData()).GetResponse(); - } - - /// - /// Makes a PATCH request to the specified . - /// - /// The base URL of the request (no query string). - /// The query string. - /// An instance of representing the raw response. - public static IHttpResponse Patch(string url, IHttpQueryString? queryString) { - return HttpRequest.Patch(url, queryString).GetResponse(); - } - - /// - /// Makes a PATCH request to the specified . - /// - /// The base URL of the request (no query string). - /// The PATCH data. - /// An instance of representing the raw response. - public static IHttpResponse Patch(string url, IHttpPostData? postData) { - return HttpRequest.Patch(url, postData).GetResponse(); - } - - /// - /// Makes a PATCH request to the specified . - /// - /// The URL of the request. - /// The query string of the request. - /// The PATCH data of the request. - /// An instance of representing the response. - public static IHttpResponse Patch(string url, IHttpQueryString? queryString, IHttpPostData? postData) { - return HttpRequest.Patch(url, queryString, postData).GetResponse(); - } - - #endregion - - #region Delete - - /// - /// Makes a HTTP DELETE request to the specified . - /// - /// The URL of the request. - /// An instance of representing the response. - public static IHttpResponse Delete(string url) { - return HttpRequest.Delete(url).GetResponse(); - } - - /// - /// Makes a DELETE request to the specified . - /// - /// The URL of the request. - /// The options for the call to the specified . - /// An instance of representing the response. - [Obsolete("Use 'GetResponse' method and 'IHttpRequestOptions' class as parameter instead.")] - public static IHttpResponse Delete(string url, IHttpGetOptions? options) { - return HttpRequest.Delete(url, options?.GetQueryString()).GetResponse(); - } - - /// - /// Makes a DELETE request to the specified . - /// - /// The URL of the request. - /// The query string of the request. - /// An instance of representing the response. - public static IHttpResponse Delete(string url, IHttpQueryString? queryString) { - return HttpRequest.Delete(url, queryString).GetResponse(); - } - - #endregion - - #region DoHttpRequest - - /// - /// Makes a HTTP request using the specified and . - /// - /// The URL of the request. - /// The HTTP method of the request. - /// The query string of the request. - /// The POST data of the request. - /// An instance of representing the response. - private static IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpQueryString? queryString, IHttpPostData? postData) { - return new HttpRequest(method, url, queryString, postData).GetResponse(); - } - - #endregion + /// The URL of the request. + /// The options for the call to the specified . + /// An instance of representing the response. + [Obsolete("Use 'GetResponse' method and 'IHttpRequestOptions' class as parameter instead.")] + public static IHttpResponse Put(string url, IHttpPostOptions? options) { + return HttpRequest.Put(url, options?.GetQueryString(), options?.GetPostData()).GetResponse(); + } + + /// + /// Makes a PUT request to the specified . + /// + /// The base URL of the request (no query string). + /// The query string. + /// An instance of representing the raw response. + public static IHttpResponse Put(string url, IHttpQueryString? queryString) { + return HttpRequest.Put(url, queryString).GetResponse(); + } + + /// + /// Makes a PUT request to the specified . + /// + /// The base URL of the request (no query string). + /// The PUT data. + /// An instance of representing the raw response. + public static IHttpResponse Put(string url, IHttpPostData? postData) { + return HttpRequest.Put(url, postData).GetResponse(); + } + + /// + /// Makes a PUT request to the specified . + /// + /// The URL of the request. + /// The query string of the request. + /// The PUT data of the request. + /// An instance of representing the response. + public static IHttpResponse Put(string url, IHttpQueryString? queryString, IHttpPostData? postData) { + return HttpRequest.Put(url, queryString, postData).GetResponse(); + } + + #endregion + + #region Patch + + /// + /// Makes a PATCH request to the specified . + /// + /// The URL of the request. + /// An instance of representing the response. + public static IHttpResponse Patch(string url) { + return HttpRequest.Patch(url).GetResponse(); + } + + /// + /// Makes a PATCH request to the specified . + /// + /// The URL of the request. + /// The options for the call to the specified . + /// An instance of representing the response. + [Obsolete("Use 'GetResponse' method and 'IHttpRequestOptions' class as parameter instead.")] + public static IHttpResponse Patch(string url, IHttpGetOptions? options) { + return HttpRequest.Patch(url, options?.GetQueryString()).GetResponse(); + } + + /// + /// Makes a PATCH request to the specified . + /// + /// The URL of the request. + /// The options for the call to the specified . + /// An instance of representing the response. + [Obsolete("Use 'GetResponse' method and 'IHttpRequestOptions' class as parameter instead.")] + public static IHttpResponse Patch(string url, IHttpPostOptions? options) { + return HttpRequest.Patch(url, options?.GetQueryString(), options?.GetPostData()).GetResponse(); + } + + /// + /// Makes a PATCH request to the specified . + /// + /// The base URL of the request (no query string). + /// The query string. + /// An instance of representing the raw response. + public static IHttpResponse Patch(string url, IHttpQueryString? queryString) { + return HttpRequest.Patch(url, queryString).GetResponse(); + } + + /// + /// Makes a PATCH request to the specified . + /// + /// The base URL of the request (no query string). + /// The PATCH data. + /// An instance of representing the raw response. + public static IHttpResponse Patch(string url, IHttpPostData? postData) { + return HttpRequest.Patch(url, postData).GetResponse(); + } + /// + /// Makes a PATCH request to the specified . + /// + /// The URL of the request. + /// The query string of the request. + /// The PATCH data of the request. + /// An instance of representing the response. + public static IHttpResponse Patch(string url, IHttpQueryString? queryString, IHttpPostData? postData) { + return HttpRequest.Patch(url, queryString, postData).GetResponse(); } + #endregion + + #region Delete + + /// + /// Makes a HTTP DELETE request to the specified . + /// + /// The URL of the request. + /// An instance of representing the response. + public static IHttpResponse Delete(string url) { + return HttpRequest.Delete(url).GetResponse(); + } + + /// + /// Makes a DELETE request to the specified . + /// + /// The URL of the request. + /// The options for the call to the specified . + /// An instance of representing the response. + [Obsolete("Use 'GetResponse' method and 'IHttpRequestOptions' class as parameter instead.")] + public static IHttpResponse Delete(string url, IHttpGetOptions? options) { + return HttpRequest.Delete(url, options?.GetQueryString()).GetResponse(); + } + + /// + /// Makes a DELETE request to the specified . + /// + /// The URL of the request. + /// The query string of the request. + /// An instance of representing the response. + public static IHttpResponse Delete(string url, IHttpQueryString? queryString) { + return HttpRequest.Delete(url, queryString).GetResponse(); + } + + #endregion + + #region DoHttpRequest + + /// + /// Makes a HTTP request using the specified and . + /// + /// The URL of the request. + /// The HTTP method of the request. + /// The query string of the request. + /// The POST data of the request. + /// An instance of representing the response. + private static IHttpResponse DoHttpRequest(HttpMethod method, string url, IHttpQueryString? queryString, IHttpPostData? postData) { + return new HttpRequest(method, url, queryString, postData).GetResponse(); + } + + #endregion + } } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/HttpUtils.cs b/src/Skybrud.Essentials.Http/HttpUtils.cs index 29817d6..3505a99 100644 --- a/src/Skybrud.Essentials.Http/HttpUtils.cs +++ b/src/Skybrud.Essentials.Http/HttpUtils.cs @@ -1,8 +1,6 @@ -namespace Skybrud.Essentials.Http { +namespace Skybrud.Essentials.Http; - /// - /// Static class with various HTTP related utility methods. - /// - public static partial class HttpUtils { } - -} \ No newline at end of file +/// +/// Static class with various HTTP related utility methods. +/// +public static partial class HttpUtils { } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/IHttpPostValue.cs b/src/Skybrud.Essentials.Http/IHttpPostValue.cs index 95c4c3b..f7487d4 100644 --- a/src/Skybrud.Essentials.Http/IHttpPostValue.cs +++ b/src/Skybrud.Essentials.Http/IHttpPostValue.cs @@ -1,26 +1,24 @@ using System.IO; -namespace Skybrud.Essentials.Http { +namespace Skybrud.Essentials.Http; + +/// +/// Class representing a value of a HTTP POST request body. +/// +public interface IHttpPostValue { /// - /// Class representing a value of a HTTP POST request body. + /// Gets the name/key of the value. /// - public interface IHttpPostValue { - - /// - /// Gets the name/key of the value. - /// - string Name { get; } - - /// - /// Writes the value to the specified . - /// - /// The stream the value should be written to. - /// The multipart boundary. - /// The characters used to indicate a new line. - /// Whether the value is the last in the request body. - void WriteToMultipartStream(Stream stream, string boundary, string newLine, bool isLast); + string Name { get; } - } + /// + /// Writes the value to the specified . + /// + /// The stream the value should be written to. + /// The multipart boundary. + /// The characters used to indicate a new line. + /// Whether the value is the last in the request body. + void WriteToMultipartStream(Stream stream, string boundary, string newLine, bool isLast); } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/IHttpRequest.cs b/src/Skybrud.Essentials.Http/IHttpRequest.cs index 4cffef7..8a3acd5 100644 --- a/src/Skybrud.Essentials.Http/IHttpRequest.cs +++ b/src/Skybrud.Essentials.Http/IHttpRequest.cs @@ -4,174 +4,172 @@ using Skybrud.Essentials.Http.Collections; using System.Threading.Tasks; -namespace Skybrud.Essentials.Http { +namespace Skybrud.Essentials.Http; + +/// +/// Interface describing a HTTP request. +/// +public interface IHttpRequest { /// - /// Interface describing a HTTP request. + /// Gets or sets the HTTP method of the request. /// - public interface IHttpRequest { - - /// - /// Gets or sets the HTTP method of the request. - /// - HttpMethod Method { get; set; } + HttpMethod Method { get; set; } - /// - /// Gets or sets the credentials (username and password) of the request. - /// - ICredentials? Credentials { get; set; } + /// + /// Gets or sets the credentials (username and password) of the request. + /// + ICredentials? Credentials { get; set; } - /// - /// Gets or sets the URL of the request. The query string can either be specified directly in the URL, or - /// separately through the property. - /// - string Url { get; set; } + /// + /// Gets or sets the URL of the request. The query string can either be specified directly in the URL, or + /// separately through the property. + /// + string Url { get; set; } - /// - /// Gets or sets the HTTP host of the request. If left blank, the host will be based on - /// instead. - /// - string? Host { get; set; } + /// + /// Gets or sets the HTTP host of the request. If left blank, the host will be based on + /// instead. + /// + string? Host { get; set; } - /// - /// Gets or sets the encoding of the request. Default is UTF-8. - /// - Encoding Encoding { get; set; } + /// + /// Gets or sets the encoding of the request. Default is UTF-8. + /// + Encoding Encoding { get; set; } #if NET_FRAMEWORK - /// - /// Gets or sets the timeout of the request. Default is 100 seconds. - /// - TimeSpan Timeout { get; set; } + /// + /// Gets or sets the timeout of the request. Default is 100 seconds. + /// + TimeSpan Timeout { get; set; } #endif - /// - /// Gets or sets the collection of headers. - /// - IHttpHeaderCollection Headers { get; set; } - - /// - /// Gets or sets the query string of the request. - /// - IHttpQueryString QueryString { get; set; } - - /// - /// Gets or sets the POST data of the request. - /// - IHttpPostData PostData { get; set; } - - /// - /// Gets or sets the to be used for the request. - /// - IHttpCookieCollection Cookies { get; set; } - - /// - /// Gets or sets the content type of the request. - /// - string? ContentType { get; set; } - - /// - /// Gets or sets the body of the request. - /// - string? Body { get; set; } - - /// - /// Gets a or sets a list of content types that are acceptable for the response - eg. text/html, - /// text/html,application/xhtml+xml or application/json. This property corresponds to the - /// Accept HTTP header. - /// - /// - /// https://en.wikipedia.org/wiki/Content_negotiation - /// - string? Accept { get; set; } - - /// - /// Gets or sets the character sets that are acceptable - eg. utf8. This property corresponds to - /// the Accept-Charset HTTP header. - /// - string? AcceptCharset { get; set; } - - /// - /// Gets or sets the a list of acceptable encodings - eg. gzip or gzip, deflate. This - /// property corresponds to the Accept-Encoding HTTP header. - /// - /// - /// https://en.wikipedia.org/wiki/HTTP_compression - /// - string? AcceptEncoding { get; set; } - - /// - /// Gets or sets the accept language header of the request - eg. en-US, en or da. This - /// property corresponds to the Accept-Language HTTP header. - /// - /// - /// https://en.wikipedia.org/wiki/Content_negotiation - /// - string? AcceptLanguage { get; set; } - - /// - /// Gets or sets the authentication credentials for HTTP authentication. This property corresponds to the - /// Authorization HTTP header. - /// - string? Authorization { get; set; } - - /// - /// Gets or sets the address of the previous web page from which a link to the currently requested page was - /// followed. (The word "referrer" has been misspelled in the RFC as well as in most implementations to the - /// point that it has become standard usage and is considered correct terminology). This property corresponds - /// to the Referer HTTP header. - /// - string? Referer { get; set; } - - /// - /// Gets or sets a string representing the user agent. This property corresponds to the User-Agent - /// HTTP header. - /// - string? UserAgent { get; set; } + /// + /// Gets or sets the collection of headers. + /// + IHttpHeaderCollection Headers { get; set; } + + /// + /// Gets or sets the query string of the request. + /// + IHttpQueryString QueryString { get; set; } + + /// + /// Gets or sets the POST data of the request. + /// + IHttpPostData PostData { get; set; } + + /// + /// Gets or sets the to be used for the request. + /// + IHttpCookieCollection Cookies { get; set; } + + /// + /// Gets or sets the content type of the request. + /// + string? ContentType { get; set; } + + /// + /// Gets or sets the body of the request. + /// + string? Body { get; set; } + + /// + /// Gets a or sets a list of content types that are acceptable for the response - eg. text/html, + /// text/html,application/xhtml+xml or application/json. This property corresponds to the + /// Accept HTTP header. + /// + /// + /// https://en.wikipedia.org/wiki/Content_negotiation + /// + string? Accept { get; set; } + + /// + /// Gets or sets the character sets that are acceptable - eg. utf8. This property corresponds to + /// the Accept-Charset HTTP header. + /// + string? AcceptCharset { get; set; } + + /// + /// Gets or sets the a list of acceptable encodings - eg. gzip or gzip, deflate. This + /// property corresponds to the Accept-Encoding HTTP header. + /// + /// + /// https://en.wikipedia.org/wiki/HTTP_compression + /// + string? AcceptEncoding { get; set; } + + /// + /// Gets or sets the accept language header of the request - eg. en-US, en or da. This + /// property corresponds to the Accept-Language HTTP header. + /// + /// + /// https://en.wikipedia.org/wiki/Content_negotiation + /// + string? AcceptLanguage { get; set; } + + /// + /// Gets or sets the authentication credentials for HTTP authentication. This property corresponds to the + /// Authorization HTTP header. + /// + string? Authorization { get; set; } + + /// + /// Gets or sets the address of the previous web page from which a link to the currently requested page was + /// followed. (The word "referrer" has been misspelled in the RFC as well as in most implementations to the + /// point that it has become standard usage and is considered correct terminology). This property corresponds + /// to the Referer HTTP header. + /// + string? Referer { get; set; } + + /// + /// Gets or sets a string representing the user agent. This property corresponds to the User-Agent + /// HTTP header. + /// + string? UserAgent { get; set; } #if NET_FRAMEWORK_OR_NET_STANDARD_2 - /// - /// Gets or sets the type of decompression that is used. - /// - DecompressionMethods AutomaticDecompression { get; set; } + /// + /// Gets or sets the type of decompression that is used. + /// + DecompressionMethods AutomaticDecompression { get; set; } - /// - /// Gets or sets the media type of the request. - /// - string? MediaType { get; set; } + /// + /// Gets or sets the media type of the request. + /// + string? MediaType { get; set; } - /// - /// Gets or sets the value of the Transfer-encoding HTTP header. - /// - string? TransferEncoding { get; set; } + /// + /// Gets or sets the value of the Transfer-encoding HTTP header. + /// + string? TransferEncoding { get; set; } - /// - /// Gets or sets the value of the Connection HTTP header. - /// - string? Connection { get; set; } + /// + /// Gets or sets the value of the Connection HTTP header. + /// + string? Connection { get; set; } - /// - /// Gets or sets the value of the Expect HTTP header. - /// - string? Expect { get; set; } + /// + /// Gets or sets the value of the Expect HTTP header. + /// + string? Expect { get; set; } #endif - /// - /// Executes the request and returns the corresponding response as an instance of . - /// - /// An instance of representing the response. - IHttpResponse GetResponse(); - - /// - /// Executes the request and returns the corresponding response as an instance of . - /// - /// An instance of representing the response. - Task GetResponseAsync(); + /// + /// Executes the request and returns the corresponding response as an instance of . + /// + /// An instance of representing the response. + IHttpResponse GetResponse(); - } + /// + /// Executes the request and returns the corresponding response as an instance of . + /// + /// An instance of representing the response. + Task GetResponseAsync(); } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/IHttpResponse.cs b/src/Skybrud.Essentials.Http/IHttpResponse.cs index e182ba5..3a78454 100644 --- a/src/Skybrud.Essentials.Http/IHttpResponse.cs +++ b/src/Skybrud.Essentials.Http/IHttpResponse.cs @@ -2,58 +2,56 @@ using System.Net; using Skybrud.Essentials.Http.Collections; -namespace Skybrud.Essentials.Http { +namespace Skybrud.Essentials.Http; + +/// +/// Interface representing a HTTP response. +/// +public interface IHttpResponse { /// - /// Interface representing a HTTP response. + /// Gets a reference to the that resulted in the response. /// - public interface IHttpResponse { - - /// - /// Gets a reference to the that resulted in the response. - /// - IHttpRequest? Request { get; } - - /// - /// Gets the status code returned by the server. - /// - HttpStatusCode StatusCode { get; } + IHttpRequest? Request { get; } - /// - /// Gets the status description returned by the server. - /// - string StatusDescription { get; } + /// + /// Gets the status code returned by the server. + /// + HttpStatusCode StatusCode { get; } - /// - /// Gets the HTTP method of the request to the server. - /// - string Method { get; } + /// + /// Gets the status description returned by the server. + /// + string StatusDescription { get; } - /// - /// Gets the content type of the response. - /// - string ContentType { get; } + /// + /// Gets the HTTP method of the request to the server. + /// + string Method { get; } - /// - /// Gets a collections of headers returned by the server. - /// - IHttpHeaderCollection Headers { get; } + /// + /// Gets the content type of the response. + /// + string ContentType { get; } - /// - /// Gets the URI of the response (may differ from the requested URI - eg. if the request was redirected). - /// - Uri ResponseUri { get; } + /// + /// Gets a collections of headers returned by the server. + /// + IHttpHeaderCollection Headers { get; } - /// - /// Gets the response body as a raw string. - /// - string Body { get; } + /// + /// Gets the URI of the response (may differ from the requested URI - eg. if the request was redirected). + /// + Uri ResponseUri { get; } - /// - /// Gets the response body as an array of . - /// - byte[] BinaryBody { get; } + /// + /// Gets the response body as a raw string. + /// + string Body { get; } - } + /// + /// Gets the response body as an array of . + /// + byte[] BinaryBody { get; } } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/OAuth/Exceptions/OAuthException.cs b/src/Skybrud.Essentials.Http/OAuth/Exceptions/OAuthException.cs index 7bfe23a..baaafef 100644 --- a/src/Skybrud.Essentials.Http/OAuth/Exceptions/OAuthException.cs +++ b/src/Skybrud.Essentials.Http/OAuth/Exceptions/OAuthException.cs @@ -1,34 +1,32 @@ using System; -namespace Skybrud.Essentials.Http.OAuth.Exceptions { +namespace Skybrud.Essentials.Http.OAuth.Exceptions; - /// - /// Class representing an OAuth exception. - /// - public class OAuthException : Exception { - - #region Properties +/// +/// Class representing an OAuth exception. +/// +public class OAuthException : Exception { - /// - /// Gets a reference to the underlying response. - /// - public HttpResponse Response { get; } + #region Properties - #endregion - - #region Constructors + /// + /// Gets a reference to the underlying response. + /// + public HttpResponse Response { get; } - /// - /// Initializes a new instance based on the specified and . - /// - /// The underlying response. - /// The message. - public OAuthException(HttpResponse response, string message) : base(message) { - Response = response; - } + #endregion - #endregion + #region Constructors + /// + /// Initializes a new instance based on the specified and . + /// + /// The underlying response. + /// The message. + public OAuthException(HttpResponse response, string message) : base(message) { + Response = response; } + #endregion + } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/OAuth/Models/OAuthAccessToken.cs b/src/Skybrud.Essentials.Http/OAuth/Models/OAuthAccessToken.cs index 96827a1..ee2d4b7 100644 --- a/src/Skybrud.Essentials.Http/OAuth/Models/OAuthAccessToken.cs +++ b/src/Skybrud.Essentials.Http/OAuth/Models/OAuthAccessToken.cs @@ -1,71 +1,69 @@ using Skybrud.Essentials.Http.Collections; -namespace Skybrud.Essentials.Http.OAuth.Models { +namespace Skybrud.Essentials.Http.OAuth.Models; - /// - /// Class representing the response body of a call to get an OAuth 1.0a access token. - /// - public class OAuthAccessToken { - - #region Properties +/// +/// Class representing the response body of a call to get an OAuth 1.0a access token. +/// +public class OAuthAccessToken { - /// - /// Gets a reference to the parent OAuth client. - /// - public OAuthClient Client { get; } + #region Properties - /// - /// Gets the access token. - /// - public string Token { get; } - - /// - /// Gets the access token secret. - /// - public string TokenSecret { get; } + /// + /// Gets a reference to the parent OAuth client. + /// + public OAuthClient Client { get; } - /// - /// Gets a reference to the query string representing the response body. - /// - public IHttpQueryString Query { get; } + /// + /// Gets the access token. + /// + public string Token { get; } - #endregion + /// + /// Gets the access token secret. + /// + public string TokenSecret { get; } - #region Constructors + /// + /// Gets a reference to the query string representing the response body. + /// + public IHttpQueryString Query { get; } - /// - /// Initializes a new instance based on the specified and . - /// - /// The parent OAuth client. - /// The query string as specified by the response body. - protected OAuthAccessToken(OAuthClient client, IHttpQueryString query) { - Client = client; - Token = query["oauth_token"]!; - TokenSecret = query["oauth_token_secret"]!; - Query = query; - } + #endregion - #endregion + #region Constructors - #region Static methods + /// + /// Initializes a new instance based on the specified and . + /// + /// The parent OAuth client. + /// The query string as specified by the response body. + protected OAuthAccessToken(OAuthClient client, IHttpQueryString query) { + Client = client; + Token = query["oauth_token"]!; + TokenSecret = query["oauth_token_secret"]!; + Query = query; + } - /// - /// Parses a query string received from the API. - /// - /// The parent OAuth client. - /// The query string. - public static OAuthAccessToken Parse(OAuthClient client, string str) { + #endregion - // Convert the query string to an IHttpQueryString - IHttpQueryString query = HttpQueryString.Parse(str); + #region Static methods - // Initialize a new instance - return new OAuthAccessToken(client, query); + /// + /// Parses a query string received from the API. + /// + /// The parent OAuth client. + /// The query string. + public static OAuthAccessToken Parse(OAuthClient client, string str) { - } + // Convert the query string to an IHttpQueryString + IHttpQueryString query = HttpQueryString.Parse(str); - #endregion + // Initialize a new instance + return new OAuthAccessToken(client, query); } + #endregion + } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/OAuth/Models/OAuthRequestToken.cs b/src/Skybrud.Essentials.Http/OAuth/Models/OAuthRequestToken.cs index 0f9edea..e558d63 100644 --- a/src/Skybrud.Essentials.Http/OAuth/Models/OAuthRequestToken.cs +++ b/src/Skybrud.Essentials.Http/OAuth/Models/OAuthRequestToken.cs @@ -1,77 +1,75 @@ using Skybrud.Essentials.Http.Collections; -namespace Skybrud.Essentials.Http.OAuth.Models { +namespace Skybrud.Essentials.Http.OAuth.Models; - /// - /// Class representing the response body of a call to get an OAuth 1.0a request token. - /// - public class OAuthRequestToken { - - #region Properties +/// +/// Class representing the response body of a call to get an OAuth 1.0a request token. +/// +public class OAuthRequestToken { - /// - /// Gets a reference to the parent OAuth client. - /// - public OAuthClient Client { get; } + #region Properties - /// - /// Gets the request token. - /// - public string Token { get; } - - /// - /// Gets the request token secret. - /// - public string TokenSecret { get; } + /// + /// Gets a reference to the parent OAuth client. + /// + public OAuthClient Client { get; } - /// - /// Is the callback confirmed? - /// - public bool IsCallbackConfirmed { get; } + /// + /// Gets the request token. + /// + public string Token { get; } - /// - /// Gets the authentication URL for this request token. - /// - public string AuthorizeUrl { get; } + /// + /// Gets the request token secret. + /// + public string TokenSecret { get; } - #endregion + /// + /// Is the callback confirmed? + /// + public bool IsCallbackConfirmed { get; } - #region Constructors + /// + /// Gets the authentication URL for this request token. + /// + public string AuthorizeUrl { get; } - /// - /// Initializes a new instance based on the specified and . - /// - /// The parent OAuth client. - /// The query string as specified by the response body. - protected OAuthRequestToken(OAuthClient client, IHttpQueryString query) { - Client = client; - Token = query["oauth_token"]!; - TokenSecret = query["oauth_token_secret"]!; - IsCallbackConfirmed = query["oauth_callback_confirmed"] == "true"; - AuthorizeUrl = client.AuthorizeUrl + "?oauth_token=" + query["oauth_token"]; - } + #endregion - #endregion + #region Constructors - #region Static methods + /// + /// Initializes a new instance based on the specified and . + /// + /// The parent OAuth client. + /// The query string as specified by the response body. + protected OAuthRequestToken(OAuthClient client, IHttpQueryString query) { + Client = client; + Token = query["oauth_token"]!; + TokenSecret = query["oauth_token_secret"]!; + IsCallbackConfirmed = query["oauth_callback_confirmed"] == "true"; + AuthorizeUrl = client.AuthorizeUrl + "?oauth_token=" + query["oauth_token"]; + } - /// - /// Parses a query string received from the API. - /// - /// The parent OAuth client. - /// The query string. - public static OAuthRequestToken Parse(OAuthClient client, string str) { + #endregion - // Convert the query string to an IHttpQueryString - IHttpQueryString query = HttpQueryString.Parse(str); + #region Static methods - // Initialize a new instance - return new OAuthRequestToken(client, query); + /// + /// Parses a query string received from the API. + /// + /// The parent OAuth client. + /// The query string. + public static OAuthRequestToken Parse(OAuthClient client, string str) { - } + // Convert the query string to an IHttpQueryString + IHttpQueryString query = HttpQueryString.Parse(str); - #endregion + // Initialize a new instance + return new OAuthRequestToken(client, query); } + #endregion + } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/OAuth/OAuthClient.cs b/src/Skybrud.Essentials.Http/OAuth/OAuthClient.cs index 6dfe881..5822325 100644 --- a/src/Skybrud.Essentials.Http/OAuth/OAuthClient.cs +++ b/src/Skybrud.Essentials.Http/OAuth/OAuthClient.cs @@ -9,364 +9,362 @@ using Skybrud.Essentials.Http.OAuth.Models; using Skybrud.Essentials.Http.OAuth.Responses; -namespace Skybrud.Essentials.Http.OAuth { +namespace Skybrud.Essentials.Http.OAuth; + +/// +/// OAuth client following the OAuth 1.0a protocol. The client will handle the necessary communication with the +/// OAuth server (Service Provider). This includes the technical part with signatures, authorization headers and +/// similar. The client can also be used for 3-legged logins. +/// +public partial class OAuthClient : HttpClient { + + #region Properties /// - /// OAuth client following the OAuth 1.0a protocol. The client will handle the necessary communication with the - /// OAuth server (Service Provider). This includes the technical part with signatures, authorization headers and - /// similar. The client can also be used for 3-legged logins. + /// Gets or sets the consumer key of your OAuth application. /// - public partial class OAuthClient : HttpClient { - - #region Properties - - /// - /// Gets or sets the consumer key of your OAuth application. - /// - public string? ConsumerKey { get; set; } - - /// - /// Gets or sets the consumer secret of your OAuth application. The consumer secret is sensitive information used to - /// identify your application. Users should never be shown this value. - /// - public string? ConsumerSecret { get; set; } - - /// - /// Gets or sets a unique/random value specifying the oauth_nonce parameter in the OAuth protocol. - /// Along with oauth_timestamp, it will make sure each request is only sent once to the OAuth - /// server (provider). - /// - /// If is enabled (default), the value for this property will automatically be updated for each request. - /// - public string? Nonce { get; set; } - - /// - /// Gets or sets the current Unix timestamp specifying the oauth_timestamp parameter in the OAuth - /// protocol. Along with , it will make sure each request is only sent once to the OAuth server (provider). - /// - /// If is enabled (default), the value for this property will automatically be updated for each request. - /// - public string? Timestamp { get; set; } - - /// - /// Gets or sets the request token or access token used to access the OAuth server on behalf of a user. - /// - public string? Token { get; set; } - - /// - /// Gets or sets the request token secret or access token secret used to access the OAuth server on behalf of a - /// user. - /// - public string? TokenSecret { get; set; } - - /// - /// Gets or sets the version of the OAuth protocol. Default is 1.0. - /// - public string? Version { get; set; } - - /// - /// Gets or sets the callback URL. This property specifies the oauth_callback parameter and is - /// used for 3-legged logins. You only need to specify this property for authentication - it is not necessary - /// toset this property when just making calls to the API. - /// - public string? Callback { get; set; } - - /// - /// Gets or sets the request token URL. As the first step of the 3-legged login process, the client must obtain - /// a request token through this URL. If possible this URL should always use HTTPS. - /// - public string? RequestTokenUrl { get; set; } - - /// - /// Gets or sets the authorization URL. As the second step of the 3-legged login process, the user is - /// redirected to this URL for authorizing the login. If possible this URL should always use HTTPS. - /// - public string? AuthorizeUrl { get; set; } - - /// - /// Gets or sets the access token URL. In the final step of the 3-legged login process, the OAuth client will - /// exchange the request token for an access token. It will do so using this URL. If possible this URL should - /// always use HTTPS. - /// - public string? AccessTokenUrl { get; set; } - - /// - /// If true, new requests will automatically reset the and - /// properties with new values. It should only be disabled for testing purposes. - /// - public bool AutoReset { get; set; } - - #endregion - - #region Constructors - - /// - /// Initializes a new OAuth client with default options. - /// - public OAuthClient() { - AutoReset = true; - Nonce = OAuthUtils.GenerateNonce(); - Timestamp = OAuthUtils.GetTimestamp(); - Version = "1.0"; - } + public string? ConsumerKey { get; set; } - /// - /// Initializes a new OAuth client with the specified and - /// . - /// - /// The consumer key of your application. - /// The consumer secret of your application. - public OAuthClient(string consumerKey, string consumerSecret) { - AutoReset = true; - ConsumerKey = consumerKey; - ConsumerSecret = consumerSecret; - Nonce = OAuthUtils.GenerateNonce(); - Timestamp = OAuthUtils.GetTimestamp(); - Version = "1.0"; - } + /// + /// Gets or sets the consumer secret of your OAuth application. The consumer secret is sensitive information used to + /// identify your application. Users should never be shown this value. + /// + public string? ConsumerSecret { get; set; } - /// - /// Initializes a new OAuth client with the specified , - /// and . - /// - /// The consumer key of your application. - /// The consumer secret of your application. - /// The callback URI of your application. - public OAuthClient(string consumerKey, string consumerSecret, string callback) { - AutoReset = true; - ConsumerKey = consumerKey; - ConsumerSecret = consumerSecret; - Callback = callback; - Nonce = OAuthUtils.GenerateNonce(); - Timestamp = OAuthUtils.GetTimestamp(); - Version = "1.0"; - } + /// + /// Gets or sets a unique/random value specifying the oauth_nonce parameter in the OAuth protocol. + /// Along with oauth_timestamp, it will make sure each request is only sent once to the OAuth + /// server (provider). + /// + /// If is enabled (default), the value for this property will automatically be updated for each request. + /// + public string? Nonce { get; set; } - #endregion + /// + /// Gets or sets the current Unix timestamp specifying the oauth_timestamp parameter in the OAuth + /// protocol. Along with , it will make sure each request is only sent once to the OAuth server (provider). + /// + /// If is enabled (default), the value for this property will automatically be updated for each request. + /// + public string? Timestamp { get; set; } - #region Member methods + /// + /// Gets or sets the request token or access token used to access the OAuth server on behalf of a user. + /// + public string? Token { get; set; } - /// - /// Updates the and properties with new values for another - /// request. If the property is true, this method will be called automatically - /// before each request to the underlying API. - /// - public virtual void Reset() { - Nonce = OAuthUtils.GenerateNonce(); - Timestamp = OAuthUtils.GetTimestamp(); - } + /// + /// Gets or sets the request token secret or access token secret used to access the OAuth server on behalf of a + /// user. + /// + public string? TokenSecret { get; set; } - /// - /// Generates the string for the authorization header based on the specified . - /// - /// The signature. - /// The generated header string. - public virtual string GenerateHeaderString(string signature) { - string oauthHeaders = "OAuth realm=\"\","; - if (string.IsNullOrEmpty(Callback) == false) oauthHeaders += "oauth_callback=\"" + EscapeDataString(Callback) + "\","; - oauthHeaders += "oauth_consumer_key=\"" + EscapeDataString(ConsumerKey) + "\","; - oauthHeaders += "oauth_nonce=\"" + EscapeDataString(Nonce) + "\","; - oauthHeaders += "oauth_signature=\"" + EscapeDataString(signature) + "\","; - oauthHeaders += "oauth_signature_method=\"HMAC-SHA1\","; - oauthHeaders += "oauth_timestamp=\"" + Timestamp + "\","; - if (string.IsNullOrEmpty(Token) == false) oauthHeaders += "oauth_token=\"" + EscapeDataString(Token) + "\","; - oauthHeaders += "oauth_version=\"" + Version + "\""; - return oauthHeaders; - } + /// + /// Gets or sets the version of the OAuth protocol. Default is 1.0. + /// + public string? Version { get; set; } - /// - /// Generates the the string of parameters used for making the signature. - /// - /// Values representing the query string. - /// Values representing the POST body. - /// The generated parameter string. - public virtual string GenerateParameterString(IHttpQueryString? queryString, IHttpPostData? body) { - - // The parameters must be alphabetically sorted - SortedDictionary sorted = new(); - - // Add parameters from the query string - if (queryString != null) { - foreach (string key in queryString.Keys) { - //if (key.StartsWith("oauth_")) continue; - sorted.Add(EscapeDataString(key), EscapeDataString(queryString[key])); - } - } + /// + /// Gets or sets the callback URL. This property specifies the oauth_callback parameter and is + /// used for 3-legged logins. You only need to specify this property for authentication - it is not necessary + /// toset this property when just making calls to the API. + /// + public string? Callback { get; set; } - // Add parameters from the POST data - if (body != null) { - foreach (string key in body.Keys) { - //if (key.StartsWith("oauth_")) continue; - sorted.Add(EscapeDataString(key), EscapeDataString(body[key])); - } - } + /// + /// Gets or sets the request token URL. As the first step of the 3-legged login process, the client must obtain + /// a request token through this URL. If possible this URL should always use HTTPS. + /// + public string? RequestTokenUrl { get; set; } - // Add OAuth values - if (string.IsNullOrEmpty(Callback) == false) sorted.Add("oauth_callback", EscapeDataString(Callback)); - sorted.Add("oauth_consumer_key", EscapeDataString(ConsumerKey)); - sorted.Add("oauth_nonce", EscapeDataString(Nonce)); - sorted.Add("oauth_signature_method", "HMAC-SHA1"); - sorted.Add("oauth_timestamp", EscapeDataString(Timestamp)); - if (string.IsNullOrEmpty(Token) == false) sorted.Add("oauth_token", EscapeDataString(Token)); - sorted.Add("oauth_version", EscapeDataString(Version)); + /// + /// Gets or sets the authorization URL. As the second step of the 3-legged login process, the user is + /// redirected to this URL for authorizing the login. If possible this URL should always use HTTPS. + /// + public string? AuthorizeUrl { get; set; } - // Merge all parameters - return sorted.Aggregate("", (current, pair) => current + ("&" + pair.Key + "=" + pair.Value)).Substring(1); + /// + /// Gets or sets the access token URL. In the final step of the 3-legged login process, the OAuth client will + /// exchange the request token for an access token. It will do so using this URL. If possible this URL should + /// always use HTTPS. + /// + public string? AccessTokenUrl { get; set; } - } + /// + /// If true, new requests will automatically reset the and + /// properties with new values. It should only be disabled for testing purposes. + /// + public bool AutoReset { get; set; } - /// - /// Generates the key used for making the signature. - /// - /// The generated signature key. - public virtual string GenerateSignatureKey() { - return EscapeDataString(ConsumerSecret ?? string.Empty) + "&" + EscapeDataString(TokenSecret ?? string.Empty); - } + #endregion + + #region Constructors + + /// + /// Initializes a new OAuth client with default options. + /// + public OAuthClient() { + AutoReset = true; + Nonce = OAuthUtils.GenerateNonce(); + Timestamp = OAuthUtils.GetTimestamp(); + Version = "1.0"; + } + + /// + /// Initializes a new OAuth client with the specified and + /// . + /// + /// The consumer key of your application. + /// The consumer secret of your application. + public OAuthClient(string consumerKey, string consumerSecret) { + AutoReset = true; + ConsumerKey = consumerKey; + ConsumerSecret = consumerSecret; + Nonce = OAuthUtils.GenerateNonce(); + Timestamp = OAuthUtils.GetTimestamp(); + Version = "1.0"; + } + + /// + /// Initializes a new OAuth client with the specified , + /// and . + /// + /// The consumer key of your application. + /// The consumer secret of your application. + /// The callback URI of your application. + public OAuthClient(string consumerKey, string consumerSecret, string callback) { + AutoReset = true; + ConsumerKey = consumerKey; + ConsumerSecret = consumerSecret; + Callback = callback; + Nonce = OAuthUtils.GenerateNonce(); + Timestamp = OAuthUtils.GetTimestamp(); + Version = "1.0"; + } + + #endregion + + #region Member methods + + /// + /// Updates the and properties with new values for another + /// request. If the property is true, this method will be called automatically + /// before each request to the underlying API. + /// + public virtual void Reset() { + Nonce = OAuthUtils.GenerateNonce(); + Timestamp = OAuthUtils.GetTimestamp(); + } + + /// + /// Generates the string for the authorization header based on the specified . + /// + /// The signature. + /// The generated header string. + public virtual string GenerateHeaderString(string signature) { + string oauthHeaders = "OAuth realm=\"\","; + if (string.IsNullOrEmpty(Callback) == false) oauthHeaders += "oauth_callback=\"" + EscapeDataString(Callback) + "\","; + oauthHeaders += "oauth_consumer_key=\"" + EscapeDataString(ConsumerKey) + "\","; + oauthHeaders += "oauth_nonce=\"" + EscapeDataString(Nonce) + "\","; + oauthHeaders += "oauth_signature=\"" + EscapeDataString(signature) + "\","; + oauthHeaders += "oauth_signature_method=\"HMAC-SHA1\","; + oauthHeaders += "oauth_timestamp=\"" + Timestamp + "\","; + if (string.IsNullOrEmpty(Token) == false) oauthHeaders += "oauth_token=\"" + EscapeDataString(Token) + "\","; + oauthHeaders += "oauth_version=\"" + Version + "\""; + return oauthHeaders; + } - /// - /// Generates the string value used for making the signature. - /// - /// The method for the HTTP request. - /// The URL of the request. - /// The query string. - /// The POST data. - /// The generated signature value. - public virtual string GenerateSignatureValue(HttpMethod method, string url, IHttpQueryString queryString, IHttpPostData body) { - return string.Format( - "{0}&{1}&{2}", - method.ToString().ToUpper(), - EscapeDataString(url.Split('#')[0].Split('?')[0]), - EscapeDataString(GenerateParameterString(queryString, body)) - ); + /// + /// Generates the the string of parameters used for making the signature. + /// + /// Values representing the query string. + /// Values representing the POST body. + /// The generated parameter string. + public virtual string GenerateParameterString(IHttpQueryString? queryString, IHttpPostData? body) { + + // The parameters must be alphabetically sorted + SortedDictionary sorted = new(); + + // Add parameters from the query string + if (queryString != null) { + foreach (string key in queryString.Keys) { + //if (key.StartsWith("oauth_")) continue; + sorted.Add(EscapeDataString(key), EscapeDataString(queryString[key])); + } } - /// - /// Generates the signature. - /// - /// The method for the HTTP request. - /// The URL of the request. - /// The query string. - /// The POST data. - /// The generated signature. - public virtual string GenerateSignature(HttpMethod method, string url, IHttpQueryString queryString, IHttpPostData body) { - HMACSHA1 hasher = new(new ASCIIEncoding().GetBytes(GenerateSignatureKey())); - return Convert.ToBase64String(hasher.ComputeHash(new ASCIIEncoding().GetBytes(GenerateSignatureValue(method, url, queryString, body)))); + // Add parameters from the POST data + if (body != null) { + foreach (string key in body.Keys) { + //if (key.StartsWith("oauth_")) continue; + sorted.Add(EscapeDataString(key), EscapeDataString(body[key])); + } } - /// - /// Gets a request token from the provider. After acquiring a request token, the user should be redirected - /// to the website of the provider for approving the application. If successful, the user will be redirected - /// back to the specified callback URL where you then can exchange the request token for an access token. - /// - /// An instance of representing the response. - public virtual OAuthRequestTokenResponse GetRequestToken() { + // Add OAuth values + if (string.IsNullOrEmpty(Callback) == false) sorted.Add("oauth_callback", EscapeDataString(Callback)); + sorted.Add("oauth_consumer_key", EscapeDataString(ConsumerKey)); + sorted.Add("oauth_nonce", EscapeDataString(Nonce)); + sorted.Add("oauth_signature_method", "HMAC-SHA1"); + sorted.Add("oauth_timestamp", EscapeDataString(Timestamp)); + if (string.IsNullOrEmpty(Token) == false) sorted.Add("oauth_token", EscapeDataString(Token)); + sorted.Add("oauth_version", EscapeDataString(Version)); - // Make the call to the API/provider - IHttpResponse response = GetRequestTokenResponse(); + // Merge all parameters + return sorted.Aggregate("", (current, pair) => current + ("&" + pair.Key + "=" + pair.Value)).Substring(1); - // Parse the response body - OAuthRequestToken body = OAuthRequestToken.Parse(this, response.Body); + } - // Parse the response - return OAuthRequestTokenResponse.ParseResponse(response, body); + /// + /// Generates the key used for making the signature. + /// + /// The generated signature key. + public virtual string GenerateSignatureKey() { + return EscapeDataString(ConsumerSecret ?? string.Empty) + "&" + EscapeDataString(TokenSecret ?? string.Empty); + } - } + /// + /// Generates the string value used for making the signature. + /// + /// The method for the HTTP request. + /// The URL of the request. + /// The query string. + /// The POST data. + /// The generated signature value. + public virtual string GenerateSignatureValue(HttpMethod method, string url, IHttpQueryString queryString, IHttpPostData body) { + return string.Format( + "{0}&{1}&{2}", + method.ToString().ToUpper(), + EscapeDataString(url.Split('#')[0].Split('?')[0]), + EscapeDataString(GenerateParameterString(queryString, body)) + ); + } - /// An instance of representing the raw response. - protected virtual IHttpResponse GetRequestTokenResponse() { + /// + /// Generates the signature. + /// + /// The method for the HTTP request. + /// The URL of the request. + /// The query string. + /// The POST data. + /// The generated signature. + public virtual string GenerateSignature(HttpMethod method, string url, IHttpQueryString queryString, IHttpPostData body) { + HMACSHA1 hasher = new(new ASCIIEncoding().GetBytes(GenerateSignatureKey())); + return Convert.ToBase64String(hasher.ComputeHash(new ASCIIEncoding().GetBytes(GenerateSignatureValue(method, url, queryString, body)))); + } - // Some error checking - if (string.IsNullOrWhiteSpace(RequestTokenUrl)) throw new PropertyNotSetException(nameof(RequestTokenUrl)); - if (string.IsNullOrWhiteSpace(AuthorizeUrl)) throw new PropertyNotSetException(nameof(AuthorizeUrl)); + /// + /// Gets a request token from the provider. After acquiring a request token, the user should be redirected + /// to the website of the provider for approving the application. If successful, the user will be redirected + /// back to the specified callback URL where you then can exchange the request token for an access token. + /// + /// An instance of representing the response. + public virtual OAuthRequestTokenResponse GetRequestToken() { - // Make the call to the API/provider - return Post(RequestTokenUrl!); + // Make the call to the API/provider + IHttpResponse response = GetRequestTokenResponse(); - } + // Parse the response body + OAuthRequestToken body = OAuthRequestToken.Parse(this, response.Body); - /// - /// Following the 3-legged authorization, you can exchange a request token for an access token - /// using this method. This is the third and final step of the authorization process. - /// - /// The verification key received after the user has accepted the app. - /// An instance of representing the response. - /// - /// https://dev.twitter.com/docs/auth/3-legged-authorization - /// - public virtual OAuthAccessTokenResponse GetAccessToken(string verifier) { + // Parse the response + return OAuthRequestTokenResponse.ParseResponse(response, body); - // Some error checking - if (string.IsNullOrWhiteSpace(verifier)) throw new ArgumentNullException(nameof(verifier)); + } - // Make the call to the API/provider - IHttpResponse response = GetAccessTokenResponse(verifier); + /// An instance of representing the raw response. + protected virtual IHttpResponse GetRequestTokenResponse() { - // Parse the response body - OAuthAccessToken body = OAuthAccessToken.Parse(this, response.Body); + // Some error checking + if (string.IsNullOrWhiteSpace(RequestTokenUrl)) throw new PropertyNotSetException(nameof(RequestTokenUrl)); + if (string.IsNullOrWhiteSpace(AuthorizeUrl)) throw new PropertyNotSetException(nameof(AuthorizeUrl)); - // Parse the response - return OAuthAccessTokenResponse.ParseResponse(response, body); + // Make the call to the API/provider + return Post(RequestTokenUrl!); - } + } - /// An instance of representing the raw response. - protected virtual IHttpResponse GetAccessTokenResponse(string verifier) { + /// + /// Following the 3-legged authorization, you can exchange a request token for an access token + /// using this method. This is the third and final step of the authorization process. + /// + /// The verification key received after the user has accepted the app. + /// An instance of representing the response. + /// + /// https://dev.twitter.com/docs/auth/3-legged-authorization + /// + public virtual OAuthAccessTokenResponse GetAccessToken(string verifier) { - // Some error checking - if (string.IsNullOrWhiteSpace(AccessTokenUrl)) throw new PropertyNotSetException(nameof(AccessTokenUrl)); + // Some error checking + if (string.IsNullOrWhiteSpace(verifier)) throw new ArgumentNullException(nameof(verifier)); - // Initialize the POST data - IHttpPostData postData = new HttpPostData(); - postData.Add("oauth_verifier", verifier); + // Make the call to the API/provider + IHttpResponse response = GetAccessTokenResponse(verifier); - // Make the call to the API/provider - return Post(AccessTokenUrl!, null, postData); + // Parse the response body + OAuthAccessToken body = OAuthAccessToken.Parse(this, response.Body); - } + // Parse the response + return OAuthAccessTokenResponse.ParseResponse(response, body); - /// - /// Helper method for generating the OAuth signature for an instance of . - /// - /// The instance of the signature should be based on. - /// The generated OAuth signature. - protected virtual string GenerateSignature(IHttpRequest request) { - if (request == null) throw new ArgumentNullException(nameof(request)); - if (string.IsNullOrWhiteSpace(request.Url)) throw new PropertyNotSetException(nameof(request.Url)); - //throw new Exception(request.Method + " => " + request.Url + " => " + request.QueryString + " => " + request.PostData); - return GenerateSignature(request.Method, request.Url, request.QueryString, request.PostData); - } + } - /// - /// Adds the OAuth 1.0a authorization header to the request. - /// - /// - protected override void PrepareHttpRequest(IHttpRequest request) { + /// An instance of representing the raw response. + protected virtual IHttpResponse GetAccessTokenResponse(string verifier) { - // Generate the signature - string signature = GenerateSignature(request); + // Some error checking + if (string.IsNullOrWhiteSpace(AccessTokenUrl)) throw new PropertyNotSetException(nameof(AccessTokenUrl)); - // Generate the header - string header = GenerateHeaderString(signature); + // Initialize the POST data + IHttpPostData postData = new HttpPostData(); + postData.Add("oauth_verifier", verifier); - // Add the authorization header - request.Headers.Headers["Authorization"] = header; + // Make the call to the API/provider + return Post(AccessTokenUrl!, null, postData); - // Make sure we reset the client (timestamp and nonce) - if (AutoReset) Reset(); + } - } + /// + /// Helper method for generating the OAuth signature for an instance of . + /// + /// The instance of the signature should be based on. + /// The generated OAuth signature. + protected virtual string GenerateSignature(IHttpRequest request) { + if (request == null) throw new ArgumentNullException(nameof(request)); + if (string.IsNullOrWhiteSpace(request.Url)) throw new PropertyNotSetException(nameof(request.Url)); + //throw new Exception(request.Method + " => " + request.Url + " => " + request.QueryString + " => " + request.PostData); + return GenerateSignature(request.Method, request.Url, request.QueryString, request.PostData); + } - /// - /// Escapes the string with the specified . - /// - /// The value to be escaped. - /// The escaped string. - public virtual string EscapeDataString(string? value) { - return Uri.EscapeDataString(value ?? string.Empty); - } + /// + /// Adds the OAuth 1.0a authorization header to the request. + /// + /// + protected override void PrepareHttpRequest(IHttpRequest request) { + + // Generate the signature + string signature = GenerateSignature(request); + + // Generate the header + string header = GenerateHeaderString(signature); - #endregion + // Add the authorization header + request.Headers.Headers["Authorization"] = header; + // Make sure we reset the client (timestamp and nonce) + if (AutoReset) Reset(); + + } + + /// + /// Escapes the string with the specified . + /// + /// The value to be escaped. + /// The escaped string. + public virtual string EscapeDataString(string? value) { + return Uri.EscapeDataString(value ?? string.Empty); } + #endregion + } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/OAuth/OAuthUtils.cs b/src/Skybrud.Essentials.Http/OAuth/OAuthUtils.cs index 3e0f636..89639b5 100644 --- a/src/Skybrud.Essentials.Http/OAuth/OAuthUtils.cs +++ b/src/Skybrud.Essentials.Http/OAuth/OAuthUtils.cs @@ -1,29 +1,27 @@ using System; using Skybrud.Essentials.Time.UnixTime; -namespace Skybrud.Essentials.Http.OAuth { +namespace Skybrud.Essentials.Http.OAuth; + +/// +/// Static class with utility methods for the OAuth implementation. +/// +public static class OAuthUtils { /// - /// Static class with utility methods for the OAuth implementation. + /// Generates a nonce (random value) used for creating the OAuth authorization header. /// - public static class OAuthUtils { - - /// - /// Generates a nonce (random value) used for creating the OAuth authorization header. - /// - /// A random value to be used for creating the OAuth authorization header. - public static string GenerateNonce() { - return Guid.NewGuid().ToString("N"); - } - - /// - /// Returns the current Unix timestamp as a string. - /// - /// The current Unix timestamp as a string. - public static string GetTimestamp() { - return ((int) UnixTimeUtils.CurrentSeconds).ToString(); - } + /// A random value to be used for creating the OAuth authorization header. + public static string GenerateNonce() { + return Guid.NewGuid().ToString("N"); + } + /// + /// Returns the current Unix timestamp as a string. + /// + /// The current Unix timestamp as a string. + public static string GetTimestamp() { + return ((int) UnixTimeUtils.CurrentSeconds).ToString(); } } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/OAuth/Responses/OAuthAccessTokenResponse.cs b/src/Skybrud.Essentials.Http/OAuth/Responses/OAuthAccessTokenResponse.cs index 1ecd458..3f5f49a 100644 --- a/src/Skybrud.Essentials.Http/OAuth/Responses/OAuthAccessTokenResponse.cs +++ b/src/Skybrud.Essentials.Http/OAuth/Responses/OAuthAccessTokenResponse.cs @@ -1,50 +1,48 @@ using System; using Skybrud.Essentials.Http.OAuth.Models; -namespace Skybrud.Essentials.Http.OAuth.Responses { +namespace Skybrud.Essentials.Http.OAuth.Responses; - /// - /// Class representing the response of a call to get an OAuth 1.0a access token. - /// - public class OAuthAccessTokenResponse : HttpResponseBase { - - #region Properties +/// +/// Class representing the response of a call to get an OAuth 1.0a access token. +/// +public class OAuthAccessTokenResponse : HttpResponseBase { - /// - /// Gets a reference to the response body. - /// - public OAuthAccessToken Body { get; protected set; } + #region Properties - #endregion - - #region Constructors + /// + /// Gets a reference to the response body. + /// + public OAuthAccessToken Body { get; protected set; } - /// - /// Initializes a new instance from the specified and . - /// - /// The raw response. - /// The object representing the response body. - protected OAuthAccessTokenResponse(IHttpResponse response, OAuthAccessToken body) : base(response) { - Body = body; - } + #endregion - #endregion + #region Constructors - #region Static methods + /// + /// Initializes a new instance from the specified and . + /// + /// The raw response. + /// The object representing the response body. + protected OAuthAccessTokenResponse(IHttpResponse response, OAuthAccessToken body) : base(response) { + Body = body; + } - /// - /// Initializes a new instance from the specified and . - /// - /// The raw response. - /// The object representing the response body. - /// An instance of . - public static OAuthAccessTokenResponse ParseResponse(IHttpResponse response, OAuthAccessToken body) { - if (response == null) throw new ArgumentNullException(nameof(response)); - return new OAuthAccessTokenResponse(response, body); - } + #endregion - #endregion + #region Static methods + /// + /// Initializes a new instance from the specified and . + /// + /// The raw response. + /// The object representing the response body. + /// An instance of . + public static OAuthAccessTokenResponse ParseResponse(IHttpResponse response, OAuthAccessToken body) { + if (response == null) throw new ArgumentNullException(nameof(response)); + return new OAuthAccessTokenResponse(response, body); } + #endregion + } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/OAuth/Responses/OAuthRequestTokenResponse.cs b/src/Skybrud.Essentials.Http/OAuth/Responses/OAuthRequestTokenResponse.cs index 38fec0d..f8faf90 100644 --- a/src/Skybrud.Essentials.Http/OAuth/Responses/OAuthRequestTokenResponse.cs +++ b/src/Skybrud.Essentials.Http/OAuth/Responses/OAuthRequestTokenResponse.cs @@ -1,50 +1,48 @@ using System; using Skybrud.Essentials.Http.OAuth.Models; -namespace Skybrud.Essentials.Http.OAuth.Responses { +namespace Skybrud.Essentials.Http.OAuth.Responses; - /// - /// Class representing the response of a call to get an OAuth 1.0a request token. - /// - public class OAuthRequestTokenResponse : HttpResponseBase { - - #region Properties +/// +/// Class representing the response of a call to get an OAuth 1.0a request token. +/// +public class OAuthRequestTokenResponse : HttpResponseBase { - /// - /// Gets a reference to the response body. - /// - public OAuthRequestToken Body { get; protected set; } + #region Properties - #endregion - - #region Constructors + /// + /// Gets a reference to the response body. + /// + public OAuthRequestToken Body { get; protected set; } - /// - /// Initializes a new instance from the specified and . - /// - /// The raw response. - /// The object representing the response body. - protected OAuthRequestTokenResponse(IHttpResponse response, OAuthRequestToken body) : base(response) { - Body = body; - } + #endregion - #endregion + #region Constructors - #region Static methods + /// + /// Initializes a new instance from the specified and . + /// + /// The raw response. + /// The object representing the response body. + protected OAuthRequestTokenResponse(IHttpResponse response, OAuthRequestToken body) : base(response) { + Body = body; + } - /// - /// Initializes a new instance from the specified and . - /// - /// The raw response. - /// The object representing the response body. - /// An instance of . - public static OAuthRequestTokenResponse ParseResponse(IHttpResponse response, OAuthRequestToken body) { - if (response == null) throw new ArgumentNullException(nameof(response)); - return new OAuthRequestTokenResponse(response, body); - } + #endregion - #endregion + #region Static methods + /// + /// Initializes a new instance from the specified and . + /// + /// The raw response. + /// The object representing the response body. + /// An instance of . + public static OAuthRequestTokenResponse ParseResponse(IHttpResponse response, OAuthRequestToken body) { + if (response == null) throw new ArgumentNullException(nameof(response)); + return new OAuthRequestTokenResponse(response, body); } + #endregion + } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/Options/IHttpGetOptions.cs b/src/Skybrud.Essentials.Http/Options/IHttpGetOptions.cs index 0ab71dc..ab8d11e 100644 --- a/src/Skybrud.Essentials.Http/Options/IHttpGetOptions.cs +++ b/src/Skybrud.Essentials.Http/Options/IHttpGetOptions.cs @@ -1,23 +1,21 @@ using Skybrud.Essentials.Http.Collections; using System; -namespace Skybrud.Essentials.Http.Options { +namespace Skybrud.Essentials.Http.Options; - /// - /// Interface representing the options of a HTTP GET request. - /// - [Obsolete("Use 'IHttpRequestOptions' class instead.")] - public interface IHttpGetOptions { - - #region Methods +/// +/// Interface representing the options of a HTTP GET request. +/// +[Obsolete("Use 'IHttpRequestOptions' class instead.")] +public interface IHttpGetOptions { - /// - /// Gets an instance of representing the GET parameters. - /// - IHttpQueryString? GetQueryString(); + #region Methods - #endregion + /// + /// Gets an instance of representing the GET parameters. + /// + IHttpQueryString? GetQueryString(); - } + #endregion } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/Options/IHttpPostOptions.cs b/src/Skybrud.Essentials.Http/Options/IHttpPostOptions.cs index 97f7ff7..37345f9 100644 --- a/src/Skybrud.Essentials.Http/Options/IHttpPostOptions.cs +++ b/src/Skybrud.Essentials.Http/Options/IHttpPostOptions.cs @@ -1,23 +1,21 @@ using Skybrud.Essentials.Http.Collections; using System; -namespace Skybrud.Essentials.Http.Options { +namespace Skybrud.Essentials.Http.Options; - /// - /// Interface representing the options of a HTTP POST request. - /// - [Obsolete("Use 'IHttpRequestOptions' class instead.")] - public interface IHttpPostOptions : IHttpGetOptions { - - #region Methods +/// +/// Interface representing the options of a HTTP POST request. +/// +[Obsolete("Use 'IHttpRequestOptions' class instead.")] +public interface IHttpPostOptions : IHttpGetOptions { - /// - /// Gets an instance of representing the POST data. - /// - IHttpPostData? GetPostData(); + #region Methods - #endregion + /// + /// Gets an instance of representing the POST data. + /// + IHttpPostData? GetPostData(); - } + #endregion } \ No newline at end of file diff --git a/src/Skybrud.Essentials.Http/Options/IHttpRequestOptions.cs b/src/Skybrud.Essentials.Http/Options/IHttpRequestOptions.cs index 17d9747..9a113da 100644 --- a/src/Skybrud.Essentials.Http/Options/IHttpRequestOptions.cs +++ b/src/Skybrud.Essentials.Http/Options/IHttpRequestOptions.cs @@ -1,16 +1,14 @@ -namespace Skybrud.Essentials.Http.Options { +namespace Skybrud.Essentials.Http.Options; + +/// +/// Options for a request. +/// +public interface IHttpRequestOptions { /// - /// Options for a request. + /// Returns a new instance for this options instance. /// - public interface IHttpRequestOptions { - - /// - /// Returns a new instance for this options instance. - /// - /// An instance of . - IHttpRequest GetRequest(); - - } + /// An instance of . + IHttpRequest GetRequest(); } \ No newline at end of file