How to expose paging data in REST export views How to allow views to export paging data along with entities?

I can set pager, and it works of course, for example my_view?page=1
displays something like

[ 
  {...},
  {...}
]


but I only get list of filtered or paginated entities, and I would like to include paging information, something like

[ 
  paging_info: [
    total: 4,
    per_page: 2,
    current_page: 1,
    ...
  ],
  data: [
    {...},
    {...}
  ]
]
Enable pager Exposed option "Allow user to control the number of items displayed in this view" in rest display, then build custom module with views style plugin - to return results and pager data, and set in rest display

short code from custom style plugin:

$ret = $this-&gt;serializer-&gt;serialize(
 [
   'results' =&gt; $rows,
   'pager' =&gt; [
     'count' =&gt; $count,
     'pages' =&gt; $pages,
     'items_per_page' =&gt; $items_per_page,
     'current_page' =&gt; $current_page,
   ]
 ],
 $content_type
);


full code in gist: https://gist.github.com/svetlio/79f3c32667b21d89ed03cdb660308668

thanks to Dan's post here: https://www.mediacurrent.com/blog/8-insights-and-useful-snippets-d8-rest-module