Summary

In this chapter, we learned that the key difference between a REST API and a SignalR real-time API is that the latter has a two-way connection with the client and can, therefore, push data to the client, as well as receive data from the client. We also learned that a SignalR real-time API uses web sockets under the hood if the server and browser support it. Web sockets are lower-level than HTTP and don't support features such as status codes and caching like HTTP does. Web sockets also don't scale across multiple servers as easily as a REST API, so REST APIs are still preferable over a real-time API for one-way communication between the client and server.

Then, we learned that the Hub base class in ASP.NET Core makes it super-easy to interact with clients. It allows us to create and interact with groups of clients, which we found very useful in our scenario. We also discovered that we can reference the hub from an API controller so that we can interact with clients when REST API requests are received. We define the endpoint for the hub in the Startup class in the Configure method in the UseEndpoints method, which is where we define the REST API controllers.

SignalR provides many client libraries for interacting with a SignalR server, including a JavaScript client that we used in our React app. After using HubConnectionBuilder to create a HubConnection object, we used this to send and receive data from the SignalR server.

In the next chapter, we are going to turn our attention back to our REST API. This time, we will focus on performance and scalability. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.42.84