Forum Discussion

Rose's avatar
Rose
New Contributor
4 years ago
Solved

ReadyAPI as a client of server sent events

Hello,


I need to use ReadyAPI as a client of server sent events.

Indeed, after sending a request I need to listen to event data (as a result of my request)  and  retrieve event data sent on SSE.

I'm using ReadyAPi pro version

 

Thanks a lot for your help

  • Rose's avatar
    Rose
    4 years ago

    Hello,

    The proposed approach does not work.

    I have addressed my question to smartbear customer service and they have  provided me a solution. 

    ReadyAPI (sopaui pro) doesn't support the SSE technology but we can implement the SSE logic inside a Groovy Script test step.

    To do that, we can use any Java library that supports SSE. Here is an example:
    https://golb.hplar.ch/2018/02/Access-Server-Sent-Events-from-Java.html

     

    It works now 🙂 

8 Replies

  • groovyguy's avatar
    groovyguy
    Champion Level 1

    Can you further define what "Server sent events" means? That's a phrase that can mean any sort of different types of events and messages. The more details you can provide the better chances that we can help!

    • Rose's avatar
      Rose
      New Contributor

      Thanks for your response.

       

      I testing an API using SSE channel to send  messages.

      Manually I test data events sent on SSE with curl client this way:

      curl -N -H "Accept: text/event-stream" https://localhost:8080/request/listen

      I need to do the same test with ReadyAPI. (listening and tracking  “event-stream” sent by the server after the request has been submitted)

       

      I have noticed that there's an event handler in ReadyAPi but I'm not sure if it can help.

      I'm quite blocked to automate this part with Ready API

       

      Thanks a lot

       

       

      • richie's avatar
        richie
        Community Hero
        Hey Rose,

        I did a bit of reading about server side events and it seems pretty straightforward (once id done some reading and reviewed the curl command youve specified anyway!)

        The events handlers in ReadyAPI! do something different and i think youre letting the word "event" obfuscate the issue, so id just ignore those for now.

        Just to ensure im clear in regards to your understanding, you have some SSE component (which equates to Server Side Events if googled) which you poke via curl, this initiates a connection allowing multiple (>=1) push messages to be returned from the endpoint and the Content-Type of these >=1 messages is set as 'text/event-stream' correct?

        That seems quite straightforward (without knowing anything about that particular datatype). I don't know what the -N switch does (other than disabling stuff) but the -H switch appears to set the Accept header value.

        You just need to setup your REST request as you would any other if converting a curl request to ReadyAPI!
        Im guessing here but id setup a GET request using the following endpoint and URI (https://localhost:8080/request/listen) and ensure you add the 'Accept' header parameter (there doesnt appear to be any other REST parameters defined according to your post) with the value of 'text/event-stream' to the request.

        You havent mentioned any authentication scheme in your post so you might need to tailor that, but your endpoint is local so the above is at least the startoff point to setup your requests in ReadyAPI! with a view toward automation. Still a bit concerned about the -N switch and what this is actually setting, but without knowing any further info about what youre testing, you should be able to start setting it up in ReadyAPI!

        Hope the above helps,

        Nice one,

        Rich
  • These replies have been moved.