Skip to content

Instantly share code, notes, and snippets.

@sergioprates
Last active November 18, 2018 12:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sergioprates/8775d2ca782b0d61ed0aa999ee985f2e to your computer and use it in GitHub Desktop.
Save sergioprates/8775d2ca782b0d61ed0aa999ee985f2e to your computer and use it in GitHub Desktop.
Criando uma API Streaming com .NET Core
[HttpPost]
public IActionResult Post(Cliente cliente)
{
//Fazer o Insert
EnviarEvento(cliente, EventoEnum.Insert);
return Ok();
}
[HttpPut]
public IActionResult Put(Cliente cliente)
{
//Fazer o Update
EnviarEvento(cliente, EventoEnum.Update);
return Ok();
}
private static async Task EnviarEvento(object dados, EventoEnum evento)
{
foreach (var client in _clients)
{
string jsonEvento = string.Format("{0}\n", JsonConvert.SerializeObject(new { dados, evento }));
await client.WriteAsync(jsonEvento);
await client.FlushAsync();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment