0

I understand the differences of Post(Add) and Put(Update) in Web Api. However, which one should I use in SignalR. When I am developing a Chat App

That is Hub Class

 public class ChatHub : Hub
 {
    ....
 }

That is ApiController Class

public class ChatClientController : ApiController
{
   // [HttpPost] or [HttpPut]??
    public bool Connect(ChatConnectionViewModel model)
    {
        //connection method
    }

   //[HttpPost] or [HttpPut] ??
    public bool SendTextMessage(MessageViewModel model)
    {
        //send message method
    }
}

My Question is:
1. When Client Side send a web api request to call Connect method, which request method should I use? Post or Put?

  1. When Client Side send a web api request to call SendTextMessagemethod, which request method should I use? Post or Put?

In addition

My goal is to send Image file via SignalR. I just got an idea from this, so I am using signalR via Web Api. Any answers?

Community
  • 1
  • 1
Gaoxin Huang
  • 178
  • 1
  • 2
  • 9
  • 1
    What are you trying to do? Are you bridging client with SignalR via WebAPI? SignalR is a technology in its own and should not follow the concept of traditional HTTP request/response. – Harry Ninh Aug 29 '16 at 03:51
  • Yes, I am bridging Client with SignalR via WebApi. I know SignalR have its own technology. In fact, my aim is to send Image via SignalR. I just got an idea from [this](http://stackoverflow.com/questions/24304673/signalr-chat-application-sending-images), so I am using signalR via Web Api – Gaoxin Huang Aug 29 '16 at 04:13
  • 1
    The approved answer in that thread said that you would need to use WebApi *separately* to upload image. So if you are following their approach, your webApi action will be a normal `post`, which before finishes, notifies the `ChatHub` (using this technique http://stackoverflow.com/questions/12188029/how-do-i-send-messages-from-server-to-client-using-signalr-hubs) to 'officially' tell client that the image upload is done. – Harry Ninh Aug 29 '16 at 05:31
  • You shouldn't upload the image using SignalR, but rather upload it the WebApi way and notify the needed users using SignalR. It is closer to the way it was built. – radu-matei Aug 29 '16 at 21:15
  • @radu-matei Thank you. I have already done this way. but which HTTP request do you use in uploading the image. – Gaoxin Huang Aug 29 '16 at 21:44
  • @radu-matei I meaned when you send an image in chat App, which method reques do you use? post or put? And, when you send a message in your chat system, which one do you use? post or put? – Gaoxin Huang Aug 29 '16 at 21:59

0 Answers0