javascriptcurlwebsocket

How to hit the WebSocket Endpoint?


I see that there is websocket endpoint which works out fins with Java tests. In logs I see

Connecting to: ws://127.0.0.1:8080/76f48a44-0af8-444c-ba97-3f1ed34afc91/tweets  

Just like any other REST API I would like to hit it via browser or curl, but when I do that I see

➜  tweetstream git:(master) ✗ curl ws://127.0.0.1:8080/b9b90525-4cd4-43de-b893-7ef107ad06c2/tweets  
curl: (1) Protocol ws not supported or disabled in libcurl  

and

➜  tweetstream git:(master) ✗ curl http://127.0.0.1:8080/b9b90525-4cd4-43de-b893-7ef107ad06c2/tweets
<html><head><title>Error</title></head><body>Not Found</body></html>%  

Is there a way to test websocket APIs with browser/curl?


Solution

  • If you mean literally to test the implementation of websockets, I found Autobahn's test suite to be very useful

    If you just want to noodle with a websocket I would recommend using the developer tools in a browser like chrome to make a connection and send/recv data:

    var ws = new WebSocket("ws://127.0.0.1:8080/76f48a44-0af8-444c-ba97-3f1ed34afc91/tweets");
    ws.onclose = function() { // thing to do on close
    };
    ws.onerror = function() { // thing to do on error
    };
    ws.onmessage = function() { // thing to do on message
    };
    ws.onopen = function() { // thing to do on open
    };
    ws.send("Hello World");