Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web API - Event Notification

I need a way for clients (C# applications) of a ASP.NET Web API to be notified of certain changes via the Web API. They don't even need to know what the changes are, just need to get a notification that something changed (at that point it's up to the client to call the API to get any specific data they may need after getting the notification). I'm not sure what a good way of accomplishing this would look like.

I'm thinking one way might be to create events and somehow have the client subscribe to those events, but I don't know how to do that through Web API.

I found some mentions of SignalR on Google, but this seems like a lot of work to implement and seems to do a lot more than I need.

All I need is for the Web API to be able to tell the client "something changed, come and get it". However, I want to avoid polling. What is the fastest/easiest way to do accomplish this?

like image 334
mayabelle Avatar asked Dec 16 '22 02:12

mayabelle


1 Answers

You really have only two options:

  1. Use SignalR or any kind of Websocket framework.
  2. Have the client apps poll the API to look for changes.

Web API is stateless by design. The API doesn't maintain any kind of connection or state information with any of the client applications. Therefore there's really no way to implement anything like a traditional C# event.

like image 162
jebar8 Avatar answered Jan 02 '23 23:01

jebar8