ashishgupta_mca
ashishgupta_mca

Reputation: 578

Rest Communication Design For Callback Mechanism

I had a use case that there is a server that can have n number of source. There can be several clients that can connect to this server and get the sources list and then can subscribe to the server to listen the source add, update and delete operation.

To implement this with REST principle, I have thought that first time when the client gets connected, the server gives the full source list along with the session id. Then with this session id, the client polls the url after a configured time interval and listen to the source updates.

The communication will looks like

Client>
 GET: /Federation/Sources

Server>>
{"sessionId":xyz,"data":{"source1"...........}}

Client>
GET: /Federation/Sources/{sessionId}

Server>>
{"sessionId":xyz,"data":{"sourceadded"...........}}

Client>
PUT: /Federation/Sources/{sessionId}
 {"data":{"Recieved"}}

This client call will then updates the server to remove the source correspond to this session id.

And then client poll continues with the session id.

Can expert please give their feedbacks or comments if this is a good approach or can there be any alternative good approach that can be follow with REST principle?

Upvotes: 0

Views: 43

Answers (1)

BillRobertson42
BillRobertson42

Reputation: 12883

Instead of passing back id's for the client to use to build the URL, simply pass back the entire URL to the client. Perhaps with more information about what the URL is for. This is the HATEOAS part of REST.

Upvotes: 1

Related Questions