26

I have an ASP .Net Core 2.2 Web API with a SignalR hub. Is it possible to call one of its methods (for example, SendMessageToAll) using Postman? The problem is that I only have the API - no frontend - and I need to test.

I tried putting the URl to my hub in Postman (api.mydomain.com/chatHub) but then I'm not really sure how to structure the body. I know SignalR uses WebSockets preferably, and I don't know if PostMan has WebSocket functionality. I believe SignalR can also do HTTP requests if WebSockets is not available, which is something Postman can do. But what body do I use? And do I use an HTTP GET or POST?

I saw a post where the person was using this body in Postman:

{
    "Target": "SendMessageToGroup",
    "Arguments": [
        "groupA",
        "hello from server"
    ]
}

So I tried the same, but when I click "Send" on postman, the SendMessageToGroup method of my hub doesn't get triggered.

enter image description here

Thanks

Fabricio Rodriguez
  • 3,241
  • 7
  • 40
  • 85
  • Yes, *possible to call one of its methods (for example, SendMessageToAll) using Postman* – Divyang Desai Jun 06 '19 at 09:35
  • 1
    Haha, thanks Div. I phrased my question wrongly, sorry about that. I meant to ask how can I do it :) I'm going to edit my question now... – Fabricio Rodriguez Jun 06 '19 at 09:38
  • @FabricioRodriguez Any working solutions? – dergroncki Jun 24 '19 at 10:27
  • 1
    @dergroncki unfortunately not. i ended up using a small little piece of Angular code to test with. It basically just connects to my SignalR hub and invokes one of the Send methods on the hub. It also displays any messages it receives. I don't really know Angular but my colleague does, so he did it for me :) – Fabricio Rodriguez Jun 24 '19 at 12:52

3 Answers3

11

Now is possible with Postman version > 8.0 using WebSocket Request block. You can grab the information in their blog post https://blog.postman.com/postman-supports-websocket-apis/

Nicolae
  • 131
  • 1
  • 5
5

Check Postman > 8. If you just inject your hub inside a controller then you can use hub's method and call it's public method from http request inside post man. Or use another app : https://stackoverflow.com/a/59543405/4751073

Mohammad Reza Mrg
  • 1,045
  • 10
  • 23
5

working for me with asp.net core 5 (didn't tested any other versions)

first of all - need to get connection id by post request

post request to get connection id

then - connect with id that you received

connection with received id

after connection - your first message must be {"protocol":"json","version":1}

first message

then - we can use this request format

new message from postman

new message in browser

need to add this specific symbol to each of your websockets requests

network with js client

when specific symbol is not added - requests does not pass

when specific symbol is not added

Roma Babiy
  • 51
  • 1
  • 2