feat(EConnectClient): add PostAsync method without body
This commit is contained in:
parent
ad9f7ef7e4
commit
3ca148f341
@ -88,4 +88,37 @@ public class EConnectClient<TError> : IEConnectClient<TError> where TError : cl
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Response<TData, TError>> PostAsync<TData>(string? route = null, object? queryParams = null, CancellationToken cancel = default)
|
||||
where TData : class
|
||||
{
|
||||
// add global query strings
|
||||
if (_options.DefaultQueryStrings is not null)
|
||||
route = route.AddQueryString(_options.DefaultQueryStrings);
|
||||
|
||||
// add query strings
|
||||
if (queryParams is not null)
|
||||
route = route.AddQueryString(queryParams.ToPropertyDictionary());
|
||||
|
||||
var res = await Http.PostAsync(route, null, cancel);
|
||||
|
||||
if (res.IsSuccessStatusCode)
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Ok = true,
|
||||
StatusCode = res.StatusCode
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
var error = await res.Content.ReadFromJsonAsync<TError>(_options.JsonSerializerOptions, cancel);
|
||||
return new()
|
||||
{
|
||||
Ok = false,
|
||||
StatusCode = res.StatusCode,
|
||||
Error = error
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user