-
Notifications
You must be signed in to change notification settings - Fork 1
WebSocket API
In order to read a vehicle, you use read, specifying the vehicle model and its id. The reponse stores the requested vehicle in the value field, here is how to read the vehicle from a socket
var vehicle;
socket.onmessage = function(msg){
var resp = msg.data;
vehicle = resp.model.value;
};
var msg = {
"read":{
"model":"Vehicle",
"id":4
}
};
socket.send(Json.stringify(msg));
For the request, you specify the Vehicle type and provide the id of the desired Vehicle
{
"read": {
"model":"Vehicle",
"id":4
}
}
The response has a model object that contains the vehicle as the value
{
"model":{
"model":"Vehicle",
"value":{
"id":4,
"longitude":2,
"latitude":7,
"capacity":6
}
}
}
A new vehicle requires a latitude, longitude, and capacity
{
"create":{
"model":"Vehicle",
"value":{
"latitude":0.123,
"longitude":0.456,
"capacitor":4
}
}
}
The response is an object with created which has the vehicle as the value
{
"created":{
"model":"Vehicle",
"value":{
"id":20,
"latitude":0.123,
"longitude":0.456,
"capacitor":4
}
}
}
An update is similar to a create except you need so specify the id of the row that you are updating, for an update, no fields are required for a vehicle.
{
"update":{
"model":"Vehicle",
"id":6,
"value":{
"latitude":1.2,
"longitude":66
}
}
}
{
"updated":{
"model":"Vehicle",
"value":{
"id":6,
"latitude":0.123,
"longitude":0.456,
"capacitor":4
}
}
}
{
"delete":{
"model":"Vehicle",
"id":4
}
}
{
"deleted":{
"model":"Vehicle",
"value":{
"id":4,
"latitude":40,
"longitude":30,
"capacity": 10
}
}
}
Reading Commodities is similar to reading vehicles, you just use Commodity instead of Vehicle for the type field
{
"read": {
"model":"Commodity",
"id":4
}
}
The response has a model object that contains the commodity
{
"model":{
"model":"Commodity",
"value":{
"id":4,
"longitude":2,
"latitude":7,
"capacity":6
}
}
}
A new commodity requires a startLatitude, startLongitude, endLatitude, endLongitude, and a param
{
"create":{
"model":"Commodity",
"value":{
"startLatitude":0.123,
"startLongitude":0.456,
"endLatitude":0.789,
"endLongitude":0.101
"param":4
}
}
}
The response is an object with created which has the Commodity
{
"created":{
"model":"Commodity",
"value":{
"id":20,
"startLatitude":0.123,
"startLongitude":0.456,
"endLatitude":0.789,
"endLongitude":0.101
"param":4
}
}
}
}
An update is similar to a create except you need so specify the id of the row that you are updating, for an update, no fields are required for a commodity.
{
"update":{
"model":"Commodity",
"id":6,
"value":{
"endLatitude":1.2,
"endLongitude":66
}
}
}
{
"updated":{
"model":"Vehicle",
"value":{
"id":6
"startLatitude":0.123,
"startLongitude":0.456,
"endLatitude":1.2,
"endLongitude":66
"param":4
}
}
}
Like a vehicle, you delete the commodity by specifying its id
{
"delete":{
"model":"Commodity",
"id":4
}
}
{
"deleted":{
"model":"Commodity",
"value":{
"id":6,
"startLatitude":0.123,
"startLongitude":0.456,
"endLatitude":1.2,
"endLongitude":66,
"param":4
}
}
}