Skip to content

Compose JSON Message

VinceZK edited this page Jul 19, 2020 · 10 revisions

An entity instance can be represented in JSON. The JSON is not just a format, but also a message that can be communicated between Client and Server, or even end to end in integration scenarios.

In the instance detail page, you can check the JSON by clicking the button 'Display in JSON'. Then a dialog will popup to show the instance detail in JSON format. JSON of a person instance

If you copy the above JSON into a HTTP request, then you will get a new person created in DB. Just like below:

POST http://localhost:3000/api/entity
Accept: */*
Cache-Control: no-cache
Content-Type: application/json

{ "ENTITY_ID": "person",
  "person": {"HEIGHT": "180", "GENDER": "male", "HOBBY":"Reading, Movie, Coding", "TYPE": "employee", "SYSTEM_ACCESS": "portal"},
  "r_user": {"USER_ID": "DH999", "USER_NAME":"John", "DISPLAY_NAME": "John Wu"},
  "r_email": [{"EMAIL": "[email protected]", "TYPE": "private", "PRIMARY":1}],
  "r_employee": {"USER_ID": "DH999", "COMPANY_ID":"Darkhouse", "DEPARTMENT_ID":"Development","TITLE":"Developer"},
  "relationships":[
    { "RELATIONSHIP_ID": "rs_user_role",
      "values":[
        { "SYNCED":0, "action": "add",
          "PARTNER_INSTANCES":[
            {"ENTITY_ID":"system_role", "ROLE_ID":"system_role", "INSTANCE_GUID":"5F50DE92743683E1ED7F964E5B9F6167"}]}
      ]
    }]
}

If you want to change the TITLE of an employee(person) from "Developer" to "Architect", then:

PUT http://localhost:3000/api/entity
Accept: */*
Cache-Control: no-cache
Content-Type: application/json

{ "ENTITY_ID": "person",
  "INSTANCE_GUID": "2FBE7490E10F11E8A90957FA46F2CECA",
  "r_employee": {"action": "update", "USER_ID": "DH001", "TITLE": "Architect"},
}

Notice the 'action' attribute, which is reserved to indicate what's the operation to the tuple of a Relation. The available values could be 'add', 'update', and 'delete'. If 'action' is not given, by default it means 'add'.

If you want to add a new address to an employee, then:

PUT http://localhost:3000/api/entity
Accept: */*
Cache-Control: no-cache``````
Content-Type: application/json

{ "ENTITY_ID": "person",
  "INSTANCE_GUID": "2FBE7490E10F11E8A90957FA46F2CECA",
  "r_address": [
     {"action": "add", "COUNTRY": "China", "CITY":"Shanghai", "POSTCODE": "777777",
      "ADDRESS_VALUE":"Building #909, YYYY Road #101",
      "TYPE": "Office", "PRIMARY":0}
      ]
}

For a comprehensive list of data manipulation, check RESTful Endpoints.

Clone this wiki locally