Aggregator

1
2
3
4
5
{
    "Name": "RESTar.Aggregator",
    "Kind": "EntityResource",
    "Methods": ["GET", "REPORT", "HEAD"]
}

The Aggregator resource is used to create custom aggregated datasets from potentially multiple requests to the web resources of a RESTar application. It accepts a request template as input – which is included as body of GET requests. It then parses the request template and makes internal API requests for all request literals contained in the template. Then the results from these API requests, which is either an object array (for GET requests) or an integer (for REPORT requests), are substituted for t he request literals in the request template. Finally the populated request template is returned as output and sent back to the client.

Simple example

For this example, we use the RESTar demo service.

generate a dynamic object containing the results of a number of other internal requests. It’s useful for generating reports of arbitrary format without sending multiple requests and stitching together the responses. The resource expects an object template to be given in GET requests. Using simple markup, the template can encode internal requests, that are then substituted for the values they return in the object structure. These internal requests are written as internal URI strings starting with (optionally) an HTTP method (if no method is given, GET is used), followed by a forward slash ('/') followed by a resource specifier or macro, conditions and so on. Non-URI values in the template are simply ignored and returned in the output as-is.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
GET https://my-server.com/rest/aggregator
Body: {
    "NrOfResources": "REPORT /resource",
    "ResourceNames": "/resource//select=name", // GET is inferred
    "PleaseIgnoreThis": 123
}
Response body: [{
    "NrOfResources": 39,
    "ResourceNames": [
        {
            "Name": "RESTar.Admin.AdminTools"
        },
        {
            "Name": "RESTar.Admin.DatabaseIndex"
        },
        {
            "Name": "RESTar.Admin.Error"
        },
        {
            "Name": "RESTar.Admin.ErrorCode"
        },
        {
            "Name": "RESTar.Admin.Macro"
        }
    ],
    "PleaseIgnoreThis": 123
}]

// REPORT requests are reduced to integers
// GET requests are reduced to JSON arrays of objects