Merge pull request #3109 from sbwalker/dev
introduce new GetJsonAsync method with default value parameter
This commit is contained in:
commit
af042bd23c
@ -22,7 +22,7 @@ namespace Oqtane.Services
|
||||
/// <inheritdoc />
|
||||
public async Task<List<Alias>> GetAliasesAsync()
|
||||
{
|
||||
List<Alias> aliases = await GetJsonAsync<List<Alias>>(ApiUrl);
|
||||
List<Alias> aliases = await GetJsonAsync<List<Alias>>(ApiUrl, Enumerable.Empty<Alias>().ToList());
|
||||
return aliases.OrderBy(item => item.Name).ToList();
|
||||
}
|
||||
|
||||
|
@ -145,10 +145,19 @@ namespace Oqtane.Services
|
||||
{
|
||||
return await response.Content.ReadFromJsonAsync<T>();
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
|
||||
protected async Task<T> GetJsonAsync<T>(string uri, T defaultvalue)
|
||||
{
|
||||
var response = await GetHttpClient().GetAsync(uri, HttpCompletionOption.ResponseHeadersRead, CancellationToken.None);
|
||||
if (await CheckResponse(response, uri) && ValidateJsonContent(response.Content))
|
||||
{
|
||||
return await response.Content.ReadFromJsonAsync<T>();
|
||||
}
|
||||
return defaultvalue;
|
||||
}
|
||||
|
||||
protected async Task PutAsync(string uri)
|
||||
{
|
||||
var response = await GetHttpClient().PutAsync(uri, null);
|
||||
|
Reference in New Issue
Block a user