that's cool. maybe something like this explicitly grouping the
metadata:
{
"dogs": [
{"dog": {"name":"Fido"}},
{"dog": {"name":"Fido Jr."}},
{"dog": {"name":"Fido III"}}
],
"_metaData": {"count":3,"limit":10,"offset":0,"q":"fido"},
"_links": {"next": "/dogs?q=fido&offset=10"}
}
I thought I’d share the problems we encountered in the hope that you can avoid them (and find your own).
First, we found the __ convention to be problematic (__metadata). The name worked well for access in JavaScript, but was not nearly as extensible as a real namespacing mechanism would have been. We are changing to real namespaces.
Second, as our resources got more complicated, we ended up with metadata strewn all over the place. For example, we support complex types (nested Json objects) and expanded relationships (more Json objects). To send type or link information for these, we ended up either having to build two parallel object graphs or toss __metadata nodes everywhere. Both are…unfortunate.
Currently, our best idea is to support templating for metadata (a bit like Json-LD does), and then define a syntax for tagging any name/value pair with metadata. Then we only use those tags in the places where we’re overriding defaults. This isn’t a perfect idea, but it works OK.
We also support metadata links (again similar to Json-LD), so that metadata can be shared between multiple requests (pulled in by reference).
Finally, it’s a good idea to place metadata first. This allows strongly-typed clients to read type information before they have to parse the values. That can reduce buffering.
That’s about all the unsolicited advice I’ll give. If you want to know more, please ask. I just want to avoid spamming you with info you don’t want.
I’ll certainly send it to the group and ask for input then!