hallo icon indicating copy to clipboard operation
hallo copied to clipboard

How to return collections

Open dimitridaras opened this issue 5 years ago • 1 comments

Hi. Is there a built-in way to output collections? If so, could you please give an example in the Readme of how? I see that you have a PagedRepresentation in the samples, but I wonder if a default Hal<IEnumerable<T>> exists as part of the framework? I'd expect the output to be similar to the following:

{
    "_links": {
        "self": {
            "href": "/people?searchParameter=foo&offset=30&limit=10"
        }
    },
    "count": 3,
    "_embedded": {
        "people": [
            {
                "firstName": "Geoffrey",
                "lastName": "Merrill",
                "_links": {
                    "self": {
                        "href": "/people/1"
                    },
                    "contacts": {
                        "href": "/people/1/contacts"
                    }
                }
            },
            {
                "firstName": "George",
                "lastName": "Murray",
                "_links": {
                    "self": {
                        "href": "/people/2"
                    },
                    "contacts": {
                        "href": "/people/2/contacts"
                    }
                }
            },
            {
                "firstName": "Giles",
                "lastName": "Munton",
                "_links": {
                    "self": {
                        "href": "/people/3"
                    },
                    "contacts": {
                        "href": "/people/3/contacts"
                    }
                }
            }
        ]
    }
}

Thanks!

dimitridaras avatar Jan 30 '20 21:01 dimitridaras

Hi @dimitridaras, there is nothing built-in today but a default Hal<IEnumerable<T>> which generates your output should be feasible. I'll have a think about how this could work.

jasonmitchell avatar Feb 24 '20 13:02 jasonmitchell