feat(EConnectClient): add PostAsync method without body

This commit is contained in:
tekh 2025-08-15 15:06:38 +02:00
parent ad9f7ef7e4
commit 3ca148f341

View File

@ -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
};
}
}
}