Last active
December 13, 2021 17:27
DaprDemoStep1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Dapr.Client; | |
using Microsoft.AspNetCore.Mvc; | |
using System.Collections.Generic; | |
using System.Net.Http; | |
using System.Threading.Tasks; | |
namespace DaprClientDemo.Controllers | |
{ | |
[Route("api/[controller]")] | |
[ApiController] | |
public class DaprController : ControllerBase | |
{ | |
[HttpGet("HttpClient")] | |
public async Task<ActionResult> GetHttpClientResultAsync() | |
{ | |
using var httpClient = DaprClient.CreateInvokeHttpClient(); | |
var result = await httpClient.GetAsync("http://webapi/WeatherForecast"); | |
var resultContent = string.Format("result is {0} {1}", result.StatusCode, await result.Content.ReadAsStringAsync()); | |
return Ok(resultContent); | |
} | |
[HttpGet("DaprClient")] | |
public async Task<ActionResult> GetDaprClientResultAsync() | |
{ | |
using var daprClient = new DaprClientBuilder().Build(); | |
var result = await daprClient.InvokeMethodAsync<IEnumerable<WeatherForecast>>(HttpMethod.Get, "webapi", "WeatherForecast"); | |
return Ok(result); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment