Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

398
Views
What is the purpose of mixing REST with SignalR instead of using SignalR only?

Before reading this: This is not a question about "Is SignalR better than REST?"


Imagine creating a new API project using .Net 5 or 6 I see many projects providing a REST API to

  • query data via GET
  • write data via POST

and SignalR hubs to notifiy the clients about changes in realtime.

Based on the docs sample for SignalR

https://docs.microsoft.com/en-us/aspnet/core/tutorials/signalr?view=aspnetcore-6.0&tabs=visual-studio#create-a-signalr-hub

public class ChatHub : Hub
{
    public async Task SendMessage(string user, string message)
    {
        await Clients.All.SendAsync("ReceiveMessage", user, message);
    }
}

clients can call actions on the server that might write data to a database. So I could replace the REST POST endpoints with hub actions.

Based on the docs sample for communication

https://docs.microsoft.com/en-us/aspnet/core/signalr/hubs?view=aspnetcore-6.0#send-messages-to-clients

I could also ask for data, e.g.

public Task CallerRequestedAllMessages()
{
    Message[] allMessages = database.ReadAllMessages(); // pseudo code

    return Clients.Caller.SendAsync("ReceiveMessages", allMessages);
}

and replace the REST GET requests.

Are there any technical reasons to keep the REST API? Of course I can't consume the API directly like so

curl -X GET --header 'Accept: application/json' 'https://my-api.com/messages'

but that shouldn't matter when creating a "real" client connecting to the hubs and it seems people are working on packages for autogenerated SignalR API documentations.

Is there anything a .Net 6 REST API project provides or solves that a SignalR project can't?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

It really depends.
Rest is between client and server.
SiglaR is between client and server PLUS (optionally) for other clients as well.

Another thing in Signalr is the ability to "push" data to client.Rest can't do that.

Another consideration is the battery. keeping a socket open takes more battery. Another consideration is the strength of the server in terms of concurrent connections limitations.

I do see the benefit of using them both depending on the scenario.

In a low reception signal env i'd use Rest. not SignalR.
In a low battery mode , I'd use Rest.not SignalR
In a one to one only communication ( client to server only) , I'd use Rest , not signalR.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!