Multiqueries with the cm endpoint

Posted on October 19, 2019

Note: this is article is on progress, explains a functionality that will be added in a newer version.

Gila CMS offers a web api for easy access at the contents of your database (https://gilacms.com/docs/cm.html)

The benefits of this api is that the same actions and parameters can be used for different data tables.

For example, we can ask for the last 20 created tasks:

/cm/list/task?limit=20&orderby[created]=desc

This request will return to us a json array of tasks, the 20 last created, doesn't matter if their status is WIP(work in progress) or DONE.

 

In fact this is not what we want. We want to get the results seperated by their status, for example 15 maximum results for TODO and DONE, and all the results for WIP.

For these case, cm api gives the option of mutiquries, we can request more than one action using an array in POST request.

For example, we can send a request at /cm with this POST data:

{
  todo: {
    action: "list",
    table: "task",
    limit: 15,
    filters: {
      status: "TODO"
    },
    orderby: {
      "created": "DESC"
    }
  },
  todo: {
    action: "list",
    table: "task",
    filters: {
      status: "WIP"
    },
    orderby: {
      "update": "DESC"
    }
  },
  done: {
    action: "list",
    table: "task",
    limit: 15,
    filters: {
      status: "DONE"
    },
    orderby: {
      "update": "DESC"
    }
  },
}