@@ -40,6 +40,30 @@ fetch('https://jsonplaceholder.typicode.com/posts')
40
40
]
41
41
```
42
42
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
+
43
67
### Create a resource
44
68
45
69
``` js
@@ -121,7 +145,7 @@ fetch('https://jsonplaceholder.typicode.com/posts/1', {
121
145
}
122
146
```
123
147
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.
125
149
126
150
### Delete a resource
127
151
@@ -131,7 +155,7 @@ fetch('https://jsonplaceholder.typicode.com/posts/1', {
131
155
})
132
156
```
133
157
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.
135
159
136
160
### Filter resources
137
161
0 commit comments