Optimizing Queries

It is highly recommend, that you use the ?fields query parameter to only select the fields you need. Not only does it help us save resources, but you also receive responses faster and in a smaller payload. You can nest this as much as you want, and our API will only spend resources on the requested data.

🤓

Improve API Response Speed by Optimizing your Queries

By default, the Rackbeat APIs return all available data fields, which can result in heavy payloads. By using the method of customizable requests in the Rackbeat application ourself, we have experienced that most "home"/"index" views had 4-6x increases in speed. Usually responses went from 400ms → 80ms, and server usage went down significantly as well.


Example 1: Get only number and name from Products
GET /api/products?fields=number,name

Example Response

{
      "products": [
          {
              "number": "1002",
              "name": "Shovel",
          },
          {
              "number": "1001",
              "name": "Axe",
          },
      ]
  }

Example 2: Get sub fields for Products
Rackbeat APIs also handle selecting sub-fields, such as getting only the name from a products unit or group. GET /api/products?fields=number,unit(name),group(name)

Example Response

{
    "products": [
        {
            "number": "1002",
            "unit": {
                "name": "pcs"
            },
            "group": {
                "name": "All items"
            }
        },
        {
            "number": "1001",
            "unit": {
                "name": "pcs"
            },
            "group": {
                "name": "Taxed items"
            }
        },
    ]
}

Example 3: Get nested child fields of Order Lines
It is also possible to go one level deeper and e.g. get only the item group name of the order's lines. GET /api/orders?fields=lines(item(group(name)))

Example Response

{
    "orders": [
        {
            "lines": [
                {
                    "item": {
                        "group": {
                            "name": "Varer m\/moms"
                        }
                    }
                }
            ]
        },
        {
            "lines": [
                {
                    "item": {
                        "group": {
                            "name": "Varer m\/moms"
                        }
                    }
                },
                {
                    "item": {
                        "group": {
                            "name": "Varer m\/moms"
                        }
                    }
                }
            ]
        },
    ]
}