Skip to content

Commit 7262fb5

Browse files
committed
Added misc async methods to HttpClient
1 parent 0c77821 commit 7262fb5

5 files changed

Lines changed: 929 additions & 0 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System;
2+
using System.Collections.Specialized;
3+
using System.Threading.Tasks;
4+
using Skybrud.Essentials.Http.Collections;
5+
6+
namespace Skybrud.Essentials.Http.Client;
7+
8+
public partial class HttpClient {
9+
10+
/// <summary>
11+
/// Makes a HTTP DELETE request to the specified <paramref name="url"/>.
12+
/// </summary>
13+
/// <param name="url">The URL of the request.</param>
14+
/// <returns>An instance of <see cref="IHttpResponse"/> representing the response.</returns>
15+
public virtual async Task<IHttpResponse> DeleteAsync(string url) {
16+
if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url));
17+
return await GetResponseAsync(HttpRequest.Delete(url));
18+
}
19+
20+
/// <summary>
21+
/// Makes a DELETE request to the specified <paramref name="url"/>.
22+
/// </summary>
23+
/// <param name="url">The URL of the request.</param>
24+
/// <param name="queryString">The query string of the request.</param>
25+
/// <returns>An instance of <see cref="IHttpResponse"/> representing the response.</returns>
26+
public virtual async Task<IHttpResponse> DeleteAsync(string url, IHttpQueryString? queryString) {
27+
if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url));
28+
return await GetResponseAsync(HttpRequest.Delete(url, queryString));
29+
}
30+
31+
/// <summary>
32+
/// Makes a DELETE request to the specified <paramref name="url"/>.
33+
/// </summary>
34+
/// <param name="url">The URL of the request.</param>
35+
/// <param name="queryString">The query string of the request.</param>
36+
/// <returns>An instance of <see cref="IHttpResponse"/> representing the response.</returns>
37+
public virtual async Task<IHttpResponse> DeleteAsync(string url, NameValueCollection? queryString) {
38+
if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url));
39+
IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString);
40+
return await GetResponseAsync(HttpRequest.Delete(url, query));
41+
}
42+
43+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System;
2+
using System.Collections.Specialized;
3+
using System.Threading.Tasks;
4+
using Skybrud.Essentials.Http.Collections;
5+
6+
namespace Skybrud.Essentials.Http.Client;
7+
8+
public partial class HttpClient {
9+
10+
/// <summary>
11+
/// Makes a HTTP GET request to the specified <paramref name="url"/>.
12+
/// </summary>
13+
/// <param name="url">The URL of the request.</param>
14+
/// <returns>An instance of <see cref="IHttpResponse"/> representing the response.</returns>
15+
public virtual async Task<IHttpResponse> GetAsync(string url) {
16+
if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url));
17+
return await GetResponseAsync(HttpRequest.Get(url));
18+
}
19+
20+
/// <summary>
21+
/// Makes a GET request to the specified <paramref name="url"/>.
22+
/// </summary>
23+
/// <param name="url">The URL of the request.</param>
24+
/// <param name="queryString">The query string of the request.</param>
25+
/// <returns>An instance of <see cref="IHttpResponse"/> representing the response.</returns>
26+
public virtual async Task<IHttpResponse> GetAsync(string url, IHttpQueryString queryString) {
27+
if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url));
28+
return await GetResponseAsync(HttpRequest.Get(url, queryString));
29+
}
30+
31+
/// <summary>
32+
/// Makes a GET request to the specified <paramref name="url"/>.
33+
/// </summary>
34+
/// <param name="url">The URL of the request.</param>
35+
/// <param name="queryString">The query string of the request.</param>
36+
/// <returns>An instance of <see cref="IHttpResponse"/> representing the response.</returns>
37+
public virtual async Task<IHttpResponse> GetAsync(string url, NameValueCollection? queryString) {
38+
if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url));
39+
IHttpQueryString? query = queryString == null ? null : new HttpQueryString(queryString);
40+
return await GetResponseAsync(HttpRequest.Get(url, query));
41+
}
42+
43+
}

0 commit comments

Comments
 (0)