Real Time API using JSON

348 Views Asked by At

I wish to send commands on a web socket to the backend. I was thinking my protocol should look like this:

Send: {cmd: "login", data: {user:"Me",id:99}} Reply: {cmd: "login", data: "OK"}

Send: {cmd: "join sensors", data: {group:1}} Reply: {cmd: "join sensors", data: "OK"}

Send: {cmd: "join actuators", data: {group:1}} Reply: {cmd: "join actuators", data: "NOK"}

I will always wait for a response before issuing a new request.

I can also receive events from the BE:

{evt:"sensor update", data: {id:1,value;20}}

Is my design sensible? Is there a more standardised approach?

0

There are 0 best solutions below