continuously recieve API response from an api endpoint. Java

29 views Asked by At

I have a rest endpoint and when I call it, I het partial responses from that api continuously. for example, I have an api /blah/v1/{streamid} and I have the following code

    public void stream(String path) {
        try {
            HttpURLConnection connection = createConnection(path);
            if (connection == null) {
                return;
            }
            BufferedReader in = new BufferedReader(
                    new InputStreamReader(connection.getInputStream()));
            String inputLine;
            while ((inputLine = in.readLine()) != null) {
                System.out.println(inputLine);
            }
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

and this

    private HttpURLConnection createConnection(String path) {
        try {
            String sUrl = ENDPOINT + path;
            URL url = new URL(sUrl);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("GET");
            connection.setRequestProperty("Content-Type", "application/json");
            return connection;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

this is basically reading line by line from the connections input stream and diplaying those.

I wanted to see if there are any capabilities like this in Vertx.

I tried using Vertx's WebClient and it does not read any data from the connection even when I am not getting the same data from the above code.

Can someone advise ?

0

There are 0 answers