MXS-1220: Express relations in JSON API style

The JSON API (http://jsonapi.org/) specifies a way to express relations in
a somewhat generic way. By moving towards a more generic schema for the
resources, it will be easier to handle the modification of the relations
between these resources.
This commit is contained in:
Markus Mäkelä
2017-04-19 10:37:40 +03:00
committed by Markus Mäkelä
parent 5b9c276123
commit b6add43bd2
3 changed files with 36 additions and 23 deletions

View File

@ -1010,10 +1010,16 @@ json_t* session_to_json(const MXS_SESSION *session, const char *host)
json_object_set_new(rval, "id", json_integer(session->ses_id));
json_object_set_new(rval, "state", json_string(session_state(session->state)));
json_t* rel = json_object();
json_t* arr = json_array();
string svc = host;
svc += "/services/";
svc += session->service->name;
json_object_set_new(rval, "service", json_string(svc.c_str()));
json_array_append(arr, json_string(svc.c_str()));
json_object_set_new(rel, "services", arr);
json_object_set_new(rval, "relationships", rel);
if (session->client_dcb->user)
{