From 32e8caacc4ab26db36f6e89da48b82f73a493bb6 Mon Sep 17 00:00:00 2001 From: jennyf19 Date: Thu, 23 Jul 2020 09:11:18 -0700 Subject: [PATCH] add async to CallWebApiAsync (#358) --- .../templates/BlazorServerWeb-CSharp/Pages/CallWebApi.razor | 2 +- .../BlazorServerWeb-CSharp/Services/DownstreamWebApi.cs | 4 ++-- .../Server/Controllers/WeatherForecastController.cs | 2 +- .../Server/Services/DownstreamWebApi.cs | 4 ++-- .../templates/RazorPagesWeb-CSharp/Pages/Index.cshtml.cs | 2 +- .../RazorPagesWeb-CSharp/Services/DownstreamWebApi.cs | 4 ++-- .../templates/StarterWeb-CSharp/Controllers/HomeController.cs | 2 +- .../templates/StarterWeb-CSharp/Services/DownstreamWebApi.cs | 4 ++-- .../WebApi-CSharp/Controllers/WeatherForecastController.cs | 2 +- .../templates/WebApi-CSharp/Services/DownstreamWebApi.cs | 4 ++-- tests/BlazorServerCallsGraph/Pages/CallWebApi.razor | 2 +- tests/BlazorServerCallsGraph/Services/DownstreamWebApi.cs | 4 ++-- 12 files changed, 18 insertions(+), 18 deletions(-) diff --git a/ProjectTemplates/templates/BlazorServerWeb-CSharp/Pages/CallWebApi.razor b/ProjectTemplates/templates/BlazorServerWeb-CSharp/Pages/CallWebApi.razor index 0be4b9a21..a597c39ee 100644 --- a/ProjectTemplates/templates/BlazorServerWeb-CSharp/Pages/CallWebApi.razor +++ b/ProjectTemplates/templates/BlazorServerWeb-CSharp/Pages/CallWebApi.razor @@ -23,6 +23,6 @@ else protected override async Task OnInitializedAsync() { - apiResult = await downstreamAPI.CallWebApi(); + apiResult = await downstreamAPI.CallWebApiAsync(); } } diff --git a/ProjectTemplates/templates/BlazorServerWeb-CSharp/Services/DownstreamWebApi.cs b/ProjectTemplates/templates/BlazorServerWeb-CSharp/Services/DownstreamWebApi.cs index ac6273a81..d2289840c 100644 --- a/ProjectTemplates/templates/BlazorServerWeb-CSharp/Services/DownstreamWebApi.cs +++ b/ProjectTemplates/templates/BlazorServerWeb-CSharp/Services/DownstreamWebApi.cs @@ -9,7 +9,7 @@ namespace BlazorServerWeb_CSharp { public interface IDownstreamWebApi { - Task CallWebApi(string relativeEndpoint = "", string[] requiredScopes = null); + Task CallWebApiAsync(string relativeEndpoint = "", string[] requiredScopes = null); } public static class DownstreamWebApiExtensions @@ -46,7 +46,7 @@ public DownstreamWebApi( /// not specified, uses scopes from the configuration /// Endpoint relative to the CalledApiUrl configuration /// A JSON string representing the result of calling the Web API - public async Task CallWebApi(string relativeEndpoint = "", string[] requiredScopes = null) + public async Task CallWebApiAsync(string relativeEndpoint = "", string[] requiredScopes = null) { string[] scopes = requiredScopes ?? _configuration["CalledApi:CalledApiScopes"]?.Split(' '); string apiUrl = (_configuration["CalledApi:CalledApiUrl"] as string)?.TrimEnd('/') + $"/{relativeEndpoint}"; diff --git a/ProjectTemplates/templates/ComponentsWebAssembly-CSharp/Server/Controllers/WeatherForecastController.cs b/ProjectTemplates/templates/ComponentsWebAssembly-CSharp/Server/Controllers/WeatherForecastController.cs index fa888f795..2126301d6 100644 --- a/ProjectTemplates/templates/ComponentsWebAssembly-CSharp/Server/Controllers/WeatherForecastController.cs +++ b/ProjectTemplates/templates/ComponentsWebAssembly-CSharp/Server/Controllers/WeatherForecastController.cs @@ -52,7 +52,7 @@ public async Task> Get() { HttpContext.VerifyUserHasAnyAcceptedScope(scopeRequiredByApi); - string downstreamApiResult = await _downstreamWebApi.CallWebApi(); + string downstreamApiResult = await _downstreamWebApi.CallWebApiAsync(); var rng = new Random(); return Enumerable.Range(1, 5).Select(index => new WeatherForecast diff --git a/ProjectTemplates/templates/ComponentsWebAssembly-CSharp/Server/Services/DownstreamWebApi.cs b/ProjectTemplates/templates/ComponentsWebAssembly-CSharp/Server/Services/DownstreamWebApi.cs index 6c7a02a0d..0c7d0fcb9 100644 --- a/ProjectTemplates/templates/ComponentsWebAssembly-CSharp/Server/Services/DownstreamWebApi.cs +++ b/ProjectTemplates/templates/ComponentsWebAssembly-CSharp/Server/Services/DownstreamWebApi.cs @@ -9,7 +9,7 @@ namespace ComponentsWebAssembly_CSharp.Server { public interface IDownstreamWebApi { - Task CallWebApi(string relativeEndpoint = "", string[] requiredScopes = null); + Task CallWebApiAsync(string relativeEndpoint = "", string[] requiredScopes = null); } public static class DownstreamWebApiExtensions @@ -46,7 +46,7 @@ public DownstreamWebApi( /// not specified, uses scopes from the configuration /// Endpoint relative to the CalledApiUrl configuration /// A JSON string representing the result of calling the Web API - public async Task CallWebApi(string relativeEndpoint = "", string[] requiredScopes = null) + public async Task CallWebApiAsync(string relativeEndpoint = "", string[] requiredScopes = null) { string[] scopes = requiredScopes ?? _configuration["CalledApi:CalledApiScopes"]?.Split(' '); string apiUrl = (_configuration["CalledApi:CalledApiUrl"] as string)?.TrimEnd('/') + $"/{relativeEndpoint}"; diff --git a/ProjectTemplates/templates/RazorPagesWeb-CSharp/Pages/Index.cshtml.cs b/ProjectTemplates/templates/RazorPagesWeb-CSharp/Pages/Index.cshtml.cs index 8052c1f76..bac649334 100644 --- a/ProjectTemplates/templates/RazorPagesWeb-CSharp/Pages/Index.cshtml.cs +++ b/ProjectTemplates/templates/RazorPagesWeb-CSharp/Pages/Index.cshtml.cs @@ -36,7 +36,7 @@ public IndexModel(ILogger logger, public async Task OnGet() { - ViewData["ApiResult"] = await _downstreamWebApi.CallWebApi(); + ViewData["ApiResult"] = await _downstreamWebApi.CallWebApiAsync(); } #elseif (GenerateGraph) private readonly GraphServiceClient _graphServiceClient; diff --git a/ProjectTemplates/templates/RazorPagesWeb-CSharp/Services/DownstreamWebApi.cs b/ProjectTemplates/templates/RazorPagesWeb-CSharp/Services/DownstreamWebApi.cs index 530167344..4806ca192 100644 --- a/ProjectTemplates/templates/RazorPagesWeb-CSharp/Services/DownstreamWebApi.cs +++ b/ProjectTemplates/templates/RazorPagesWeb-CSharp/Services/DownstreamWebApi.cs @@ -9,7 +9,7 @@ namespace Company.WebApplication1 { public interface IDownstreamWebApi { - Task CallWebApi(string relativeEndpoint = "", string[] requiredScopes = null); + Task CallWebApiAsync(string relativeEndpoint = "", string[] requiredScopes = null); } public static class DownstreamWebApiExtensions @@ -46,7 +46,7 @@ public DownstreamWebApi( /// not specified, uses scopes from the configuration /// Endpoint relative to the CalledApiUrl configuration /// A JSON string representing the result of calling the Web API - public async Task CallWebApi(string relativeEndpoint = "", string[] requiredScopes = null) + public async Task CallWebApiAsync(string relativeEndpoint = "", string[] requiredScopes = null) { string[] scopes = requiredScopes ?? _configuration["CalledApi:CalledApiScopes"]?.Split(' '); string apiUrl = (_configuration["CalledApi:CalledApiUrl"] as string)?.TrimEnd('/') + $"/{relativeEndpoint}"; diff --git a/ProjectTemplates/templates/StarterWeb-CSharp/Controllers/HomeController.cs b/ProjectTemplates/templates/StarterWeb-CSharp/Controllers/HomeController.cs index fb9ce647f..99cfc09b1 100644 --- a/ProjectTemplates/templates/StarterWeb-CSharp/Controllers/HomeController.cs +++ b/ProjectTemplates/templates/StarterWeb-CSharp/Controllers/HomeController.cs @@ -41,7 +41,7 @@ public HomeController(ILogger logger, [AuthorizeForScopes(ScopeKeySection = "CalledApi:CalledApiScopes")] public async Task Index() { - ViewData["ApiResult"] = await _downstreamWebApi.CallWebApi(); + ViewData["ApiResult"] = await _downstreamWebApi.CallWebApiAsync(); return View(); } #elseif (GenerateGraph) diff --git a/ProjectTemplates/templates/StarterWeb-CSharp/Services/DownstreamWebApi.cs b/ProjectTemplates/templates/StarterWeb-CSharp/Services/DownstreamWebApi.cs index 530167344..4806ca192 100644 --- a/ProjectTemplates/templates/StarterWeb-CSharp/Services/DownstreamWebApi.cs +++ b/ProjectTemplates/templates/StarterWeb-CSharp/Services/DownstreamWebApi.cs @@ -9,7 +9,7 @@ namespace Company.WebApplication1 { public interface IDownstreamWebApi { - Task CallWebApi(string relativeEndpoint = "", string[] requiredScopes = null); + Task CallWebApiAsync(string relativeEndpoint = "", string[] requiredScopes = null); } public static class DownstreamWebApiExtensions @@ -46,7 +46,7 @@ public DownstreamWebApi( /// not specified, uses scopes from the configuration /// Endpoint relative to the CalledApiUrl configuration /// A JSON string representing the result of calling the Web API - public async Task CallWebApi(string relativeEndpoint = "", string[] requiredScopes = null) + public async Task CallWebApiAsync(string relativeEndpoint = "", string[] requiredScopes = null) { string[] scopes = requiredScopes ?? _configuration["CalledApi:CalledApiScopes"]?.Split(' '); string apiUrl = (_configuration["CalledApi:CalledApiUrl"] as string)?.TrimEnd('/') + $"/{relativeEndpoint}"; diff --git a/ProjectTemplates/templates/WebApi-CSharp/Controllers/WeatherForecastController.cs b/ProjectTemplates/templates/WebApi-CSharp/Controllers/WeatherForecastController.cs index fb8bf854a..584c64869 100644 --- a/ProjectTemplates/templates/WebApi-CSharp/Controllers/WeatherForecastController.cs +++ b/ProjectTemplates/templates/WebApi-CSharp/Controllers/WeatherForecastController.cs @@ -54,7 +54,7 @@ public async Task> Get() { HttpContext.VerifyUserHasAnyAcceptedScope(scopeRequiredByApi); - string downstreamApiResult = await _downstreamWebApi.CallWebApi(); + string downstreamApiResult = await _downstreamWebApi.CallWebApiAsync(); var rng = new Random(); return Enumerable.Range(1, 5).Select(index => new WeatherForecast diff --git a/ProjectTemplates/templates/WebApi-CSharp/Services/DownstreamWebApi.cs b/ProjectTemplates/templates/WebApi-CSharp/Services/DownstreamWebApi.cs index 530167344..4806ca192 100644 --- a/ProjectTemplates/templates/WebApi-CSharp/Services/DownstreamWebApi.cs +++ b/ProjectTemplates/templates/WebApi-CSharp/Services/DownstreamWebApi.cs @@ -9,7 +9,7 @@ namespace Company.WebApplication1 { public interface IDownstreamWebApi { - Task CallWebApi(string relativeEndpoint = "", string[] requiredScopes = null); + Task CallWebApiAsync(string relativeEndpoint = "", string[] requiredScopes = null); } public static class DownstreamWebApiExtensions @@ -46,7 +46,7 @@ public DownstreamWebApi( /// not specified, uses scopes from the configuration /// Endpoint relative to the CalledApiUrl configuration /// A JSON string representing the result of calling the Web API - public async Task CallWebApi(string relativeEndpoint = "", string[] requiredScopes = null) + public async Task CallWebApiAsync(string relativeEndpoint = "", string[] requiredScopes = null) { string[] scopes = requiredScopes ?? _configuration["CalledApi:CalledApiScopes"]?.Split(' '); string apiUrl = (_configuration["CalledApi:CalledApiUrl"] as string)?.TrimEnd('/') + $"/{relativeEndpoint}"; diff --git a/tests/BlazorServerCallsGraph/Pages/CallWebApi.razor b/tests/BlazorServerCallsGraph/Pages/CallWebApi.razor index ba8ce50da..2ea53c2c7 100644 --- a/tests/BlazorServerCallsGraph/Pages/CallWebApi.razor +++ b/tests/BlazorServerCallsGraph/Pages/CallWebApi.razor @@ -23,6 +23,6 @@ else protected override async Task OnInitializedAsync() { - apiResult = await downstreamAPI.CallWebApi(); + apiResult = await downstreamAPI.CallWebApiAsync(); } } diff --git a/tests/BlazorServerCallsGraph/Services/DownstreamWebApi.cs b/tests/BlazorServerCallsGraph/Services/DownstreamWebApi.cs index d1925dbf9..26646081f 100644 --- a/tests/BlazorServerCallsGraph/Services/DownstreamWebApi.cs +++ b/tests/BlazorServerCallsGraph/Services/DownstreamWebApi.cs @@ -12,7 +12,7 @@ namespace blazor { public interface IDownstreamWebApi { - Task CallWebApi(string relativeEndpoint = "", string[] requiredScopes = null); + Task CallWebApiAsync(string relativeEndpoint = "", string[] requiredScopes = null); } public static class DownstreamWebApiExtensions @@ -49,7 +49,7 @@ public DownstreamWebApi( /// not specified, uses scopes from the configuration /// Endpoint relative to the CalledApiUrl configuration /// A JSON string representing the result of calling the Web API - public async Task CallWebApi(string relativeEndpoint = "", string[] requiredScopes = null) + public async Task CallWebApiAsync(string relativeEndpoint = "", string[] requiredScopes = null) { string[] scopes = requiredScopes ?? _configuration["CalledApi:CalledApiScopes"]?.Split(' '); string apiUrl = (_configuration["CalledApi:CalledApiUrl"] as string)?.TrimEnd('/') + $"/{relativeEndpoint}";