Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting number of records from JSON server end point

I'm creating a mock application with JSON server as the backend and I'm wondering if it is possible to get the total number of records contained at an end point without loading all the records themselves? Assuming the db.json file looks like the JSON snippet below, how would I find out that the end point only has one record without fetching the record itself, provided it's possible?

    {
      "books": [{
      "title": "The Da Vinci Code",
      "rating": "0"}]
    }
like image 994
Happy Koala Avatar asked Dec 15 '22 00:12

Happy Koala


1 Answers

You can simply retrieve the X-Total-Count header

This is a screen-shot of a response headers returned by JSON Server when enabling pagination i.e using the _page parameter (e.g. localhost:3000/contacts?_page=1)

like image 191
Ahmed Avatar answered Dec 16 '22 12:12

Ahmed