Let's say I have a request to get all items in a database.
I want to serialize the data to JSON to the client, but I don't want to
read the entire database into an array/Json object, and then write it out.
I can do something like:
void getData()
{
// set up database range
auto r = getData();
bool first = true;
writeToResponse("[");
foreach(row; r)
{
if(!first) writeToResponse(","); else first = false;
serializeRow(row);
}
writeToResponse("]");
}
Now, if I examine vibe.data.json, I can serialize complete json objects.
I can probably handle serializing each row this way. However, what I
think would be fantastic is to serialize the entire range to JSON,
having each row serialized automatically and lazily.
Does such a function exist? There's HTTPServerResponse.writeJsonBody,
but it needs a complete in-memory object.
-Steve