first commit -push
This commit is contained in:
36
RobotNet.Clients/HttpClientExtensions.cs
Normal file
36
RobotNet.Clients/HttpClientExtensions.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Net.Http.Json;
|
||||
|
||||
namespace RobotNet.Clients;
|
||||
|
||||
public static class HttpClientExtensions
|
||||
{
|
||||
public static async Task<TValue?> PostFromJsonAsync<TValue>(this HttpClient client, string requestUri, object value)
|
||||
{
|
||||
var response = await client.PostAsJsonAsync(requestUri, value);
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
return await response.Content.ReadFromJsonAsync<TValue>();
|
||||
}
|
||||
return default;
|
||||
}
|
||||
|
||||
public static async Task<TValue?> PutFromJsonAsync<TValue>(this HttpClient client, string requestUri, object value)
|
||||
{
|
||||
var response = await client.PutAsJsonAsync(requestUri, value);
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
return await response.Content.ReadFromJsonAsync<TValue>();
|
||||
}
|
||||
return default;
|
||||
}
|
||||
|
||||
public static async Task<TValue?> PatchFromJsonAsync<TValue>(this HttpClient client, string requestUri, object value)
|
||||
{
|
||||
var response = await client.PatchAsJsonAsync(requestUri, value);
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
return await response.Content.ReadFromJsonAsync<TValue>();
|
||||
}
|
||||
return default;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user