Die Klasse Method (Http) und unnötige Erweiterungen wurden entfernt.
This commit is contained in:
parent
ba94f4689a
commit
8d38e883df
@ -8,22 +8,6 @@ namespace DigitalData.Core.Client
|
||||
/// </summary>
|
||||
public static class HttpExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Fetches data from the specified URL using the given HTTP method.
|
||||
/// </summary>
|
||||
/// <param name="url">The URL to fetch data from.</param>
|
||||
/// <param name="method">The HTTP method to use for the request. Defaults to GET.</param>
|
||||
/// <returns>A task representing the HTTP response message.</returns>
|
||||
public static async Task<HttpResponseMessage> Fetch(this string url, Method method = Method.GET)
|
||||
{
|
||||
using HttpClient client = new();
|
||||
return method switch
|
||||
{
|
||||
Method.GET => await client.GetAsync(url),
|
||||
_ => throw new NotImplementedException(nameof(method)),
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the content of the HTTP response message as a string.
|
||||
/// </summary>
|
||||
@ -61,39 +45,6 @@ namespace DigitalData.Core.Client
|
||||
return JsonConvert.DeserializeObject<dynamic>(json) ?? string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetches data from the specified URL using the given HTTP method and reads the response content as a string.
|
||||
/// </summary>
|
||||
/// <param name="url">The URL to fetch data from.</param>
|
||||
/// <param name="method">The HTTP method to use for the request. Defaults to GET.</param>
|
||||
/// <returns>A task representing the response content as a string.</returns>
|
||||
public static async Task<string> FetchText(this string url, Method method = Method.GET) => await url.Fetch(method: method).ThenAsync(Text);
|
||||
|
||||
/// <summary>
|
||||
/// Fetches data from the specified URL using the given HTTP method and deserializes the response content to a specified type.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type to deserialize the response content to.</typeparam>
|
||||
/// <param name="url">The URL to fetch data from.</param>
|
||||
/// <param name="method">The HTTP method to use for the request. Defaults to GET.</param>
|
||||
/// <returns>A task representing the deserialized response content.</returns>
|
||||
public static async Task<T?> FetchJson<T>(this string url, Method method = Method.GET) => await url.Fetch(method: method).ThenAsync(Json<T>);
|
||||
|
||||
/// <summary>
|
||||
/// Fetches data from the specified URL using the given HTTP method and deserializes the response content to a dynamic object.
|
||||
/// </summary>
|
||||
/// <param name="url">The URL to fetch data from.</param>
|
||||
/// <param name="method">The HTTP method to use for the request. Defaults to GET.</param>
|
||||
/// <returns>A task representing the deserialized response content as a dynamic object.</returns>
|
||||
public static async Task<dynamic> FetchJson(this string url, Method method = Method.GET) => await url.Fetch(method: method).ThenAsync(Json);
|
||||
|
||||
/// <summary>
|
||||
/// Fetches data from the specified URL using the given HTTP method and deserializes the response content to a list of dynamic objects.
|
||||
/// </summary>
|
||||
/// <param name="url">The URL to fetch data from.</param>
|
||||
/// <param name="method">The HTTP method to use for the request. Defaults to GET.</param>
|
||||
/// <returns>A task representing the deserialized response content as a list of dynamic objects.</returns>
|
||||
public static async Task<IEnumerable<dynamic>> FetchJsonList(this string url, Method method = Method.GET) => await url.Fetch(method: method).ThenAsync(JsonList);
|
||||
|
||||
/// <summary>
|
||||
/// Executes an action when a task is completed.
|
||||
/// </summary>
|
||||
|
||||
@ -1,7 +0,0 @@
|
||||
namespace DigitalData.Core.Client
|
||||
{
|
||||
public enum Method
|
||||
{
|
||||
GET
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user