@@ -40,6 +40,30 @@ fetch('https://jsonplaceholder.typicode.com/posts')
4040]
4141```
4242
43+ ### Paginate all resources
44+
45+ Use ` _page ` and optionally ` _limit ` to paginate returned data.
46+
47+ In the ` link ` header you'll get ` "first" ` , ` "prev" ` , ` "next" ` and ` "last" ` links.
48+
49+ _ Source:_ https://github.com/typicode/json-server/blob/master/README.md#paginate
50+
51+ ``` js
52+ fetch (' https://jsonplaceholder.typicode.com/posts?_page=1&_limit=2' )
53+ .then (async response => {
54+ const link = response .headers .get (' link' )
55+ const json = await response .json ()
56+ console .log (link, json)
57+ })
58+
59+ // Output
60+ ' <http://jsonplaceholder.typicode.com/posts?_page=1&_limit=2>; rel="first", <http://jsonplaceholder.typicode.com/posts?_page=2&_limit=2>; rel="next", <http://jsonplaceholder.typicode.com/posts?_page=50&_limit=2>; rel="last"'
61+ [
62+ { id: 1 , title: ' [...]' /* ... */ },
63+ { id: 2 , title: ' [...]' /* ... */ }
64+ ]
65+ ```
66+
4367### Create a resource
4468
4569``` js
@@ -121,7 +145,7 @@ fetch('https://jsonplaceholder.typicode.com/posts/1', {
121145}
122146```
123147
124- Important: the resource will not be really updated on the server but it will be faked as if.
148+ Important: the resource will not be really updated on the server but it will be faked as if.
125149
126150### Delete a resource
127151
@@ -131,7 +155,7 @@ fetch('https://jsonplaceholder.typicode.com/posts/1', {
131155})
132156```
133157
134- Important: the resource will not be really deleted on the server but it will be faked as if.
158+ Important: the resource will not be really deleted on the server but it will be faked as if.
135159
136160### Filter resources
137161
0 commit comments