The Write() method calls an API asking to perform a writing operation on the Database table the API works with. |
Result The UniREST Server application will write a new record into the Database table and reply with a confirmation. |
_ = #UniRESTClient.Async#.$Write$(%api, tableData, callBack%);
api|string
The API address, under the API class.
__
tableData|object
Optional values to send to the server. It must be an instance of the table class in use.
__
callBack|Action<bool>
The function to call on operation completed.
bool
true if the operation is completed, false if a system error occurred.
Example
“weapons/add” API
This API writes a new record into the “weapon” Database table. All the table columns (player_id, name, attack) are set as “Write”. This means that the API must be called sending those parameters. The API will add a new record with that 3 values.
Write() method
In this example, the Write() method calls the API.weapons_add sending the data the API expects to receive. The method will return true if the new record has been written into the “weapon” Database table, false otherwise.
var result = UniRESTClient.Async.Write(
API.weapons_add,
new DB.Weapon
{
player_id = UniRESTClient.UserID,
name = "Axe",
attack = 1000
},
(bool ok) =>
{
if (ok)
{
Debug.Log("Written! Record ID: " + UniRESTClient.DBResponse);
}
else
{
Debug.Log("Writing failed");
}
}
);
“Weapon” Database table
The Database table now contains a new record.