user3699711
user3699711

Reputation: 49

How do listen rest api with websocket client

Basically i want to listen my rest api calls. Like when somebody is sending data to my rest api. (ex: http://localhost:8080/api/people) Then websocket client listen and can get response from that address, if somebody is call that address. (like when you use postman to get response from rest api then websocet client can listen that response to.). I am littlebit lost, i dont know how to listen my rest api with websocket client. i have tried "java Socket" but then i get connectionjava.net.UnknownHostException error. Any suggestions or example how do create that websocket client that can listen rest api? Websocken client have to be simple java program that can be run from cmd.

Upvotes: 0

Views: 1322

Answers (1)

Guardian
Guardian

Reputation: 162

you can use javax.websocket and implement an endpoint. you can then connect to this endpoint. when you connect, you can save your session as well in a synchronized way (CopyonWriteList<T> for example). When your REST API is called, you can access the list of WebSocket sessions and send the data you want to return as your response of REST API back to the WebSocket client. I don't know what framework you are using, but you can also use aspects.

Upvotes: 1

Related Questions