Is it possible to call a SignalR Hub from Postman
Asked Answered
C

3

36

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

Croatia answered 6/6, 2019 at 9:11 Comment(0)
C
6

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://mcmap.net/q/66701/-websocket-connections-with-postman

Comstock answered 15/7, 2020 at 3:1 Comment(1)
This is no longer the correct answer, see above, web sockets are now supported in the tool. circa 2021Narcotic
I
20

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

---- UPDATE

{"protocol":"json","version":1} The special box at the end is critical here is a link to one that you can copy into the postman message: unicodeplus.com/U+001E. Thx David McDermott for his comment.

---- UPDATE

Intruction on Medium (no POST request needed)

Interrogate answered 6/3, 2022 at 14:48 Comment(5)
While the top scored answer is correct, this post helped me with some of the SignalR specific steps necessary in order to connect via Postman.Koh
What is the [] character?Jebel
@EricAmshukov use Js client to get it. I can not paste it here i.sstatic.net/pA02m.pngInterrogate
@EricAmshukov it should be this one , record separator, U+001E 30 036 Record Separator RS.. But alt+30 does not work on my computer (gets ▲).. I am not sure why. E.g. Console.WriteLine('\u001E'); and C&P does.Bixby
{"protocol":"json","version":1} The special box at the end is critical here is a link to one that you can copy into the postman message: unicodeplus.com/U+001E This should be added to the answer.Masjid
A
17

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/

Abuttal answered 26/5, 2021 at 15:5 Comment(3)
Thank you for your answer. It'd be nice if you could some example code.Disarm
I edited my answer with the link to their blog post in order to not be redundantAbuttal
CLARIFICATION: This blog post says it's support 8.5 and above: blog.postman.com/postman-supports-websocket-apisNarcotic
C
6

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://mcmap.net/q/66701/-websocket-connections-with-postman

Comstock answered 15/7, 2020 at 3:1 Comment(1)
This is no longer the correct answer, see above, web sockets are now supported in the tool. circa 2021Narcotic

© 2022 - 2024 — McMap. All rights reserved.