Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

407
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda