Skip to content

Commit 94b534c

Browse files
authored
Expand http connector recipe with pagination example (#378)
1 parent 2755370 commit 94b534c

2 files changed

Lines changed: 86 additions & 1 deletion

File tree

http/README.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,82 @@ FROM tvmaze
184184
WHERE request_path = '/shows/82';
185185
```
186186

187+
## Pagination
188+
189+
The HTTP connector supports automatic pagination for REST APIs that return data across multiple pages. This recipe includes a second dataset that demonstrates query-parameter pagination with the [DummyJSON Products API](https://dummyjson.com/docs/products).
190+
191+
### Configuration
192+
193+
The `products` dataset in `spicepod.yaml` uses query-parameter pagination:
194+
195+
```yaml
196+
datasets:
197+
- from: https://dummyjson.com/products
198+
name: products
199+
params:
200+
pagination: enabled
201+
pagination_query_params: "skip={offset}&limit={limit}"
202+
pagination_page_size: "30"
203+
pagination_data_pointer: "/products"
204+
pagination_max_pages: "10"
205+
```
206+
207+
- **`pagination: enabled`** — Turns on pagination.
208+
- **`pagination_query_params`** — Template with `{offset}` and `{limit}` variables. Spice expands these automatically for each page (`skip=0&limit=30`, `skip=30&limit=30`, …).
209+
- **`pagination_page_size`** — Number of items per page. Also determines when to stop: if a page returns fewer rows than this value, pagination is complete.
210+
- **`pagination_max_pages`** — Safety limit on the number of pages to fetch.
211+
212+
### Querying Paginated Data
213+
214+
Count all products fetched across pages:
215+
216+
```sql
217+
SELECT count(*) FROM products;
218+
```
219+
220+
```console
221+
+----------+
222+
| count(*) |
223+
+----------+
224+
| 194 |
225+
+----------+
226+
```
227+
228+
All 194 products are returned transparently — Spice fetches 7 pages (30 items each, except the last page with 14) and combines them into a single result set.
229+
230+
Inspect products and observe how `request_query` changes as rows span pages:
231+
232+
```sql
233+
SELECT request_query,
234+
json_get_str(content, 'title') AS title,
235+
json_get_float(content, 'price') AS price
236+
FROM products
237+
LIMIT 35;
238+
```
239+
240+
```console
241+
+------------------+-------------------------------------------+---------+
242+
| request_query | title | price |
243+
+------------------+-------------------------------------------+---------+
244+
| skip=0&limit=30 | Essence Mascara Lash Princess | 9.99 |
245+
| skip=0&limit=30 | Eyeshadow Palette with Mirror | 19.99 |
246+
| skip=0&limit=30 | Powder Canister | 14.99 |
247+
| skip=0&limit=30 | Red Lipstick | 12.99 |
248+
| skip=0&limit=30 | Red Nail Polish | 8.99 |
249+
| ... | ... | ... |
250+
| skip=0&limit=30 | Kiwi | 2.49 |
251+
| skip=30&limit=30 | Lemon | 0.79 |
252+
| skip=30&limit=30 | Milk | 3.49 |
253+
| skip=30&limit=30 | Mulberry | 4.99 |
254+
| skip=30&limit=30 | Nescafe Coffee | 7.99 |
255+
| skip=30&limit=30 | Potatoes | 2.29 |
256+
+------------------+-------------------------------------------+---------+
257+
```
258+
259+
The first 30 rows come from page 1 (`skip=0&limit=30`), then rows from page 2 (`skip=30&limit=30`) follow automatically.
260+
261+
For the full pagination parameter reference, see the [HTTP Data Connector documentation](https://docs.spiceai.org/components/data-connectors/https#pagination-parameters).
262+
187263
## Dynamic HTTP Connector Features
188264

189265
The HTTP connector provides powerful dynamic capabilities through special metadata fields that allow you to construct HTTP requests dynamically via SQL queries.

http/spicepod.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
version: v1
22
kind: Spicepod
3-
name: http_tvmaze
3+
name: http_sample
44

55
datasets:
66
- from: https://api.tvmaze.com
@@ -10,3 +10,12 @@ datasets:
1010
client_timeout: 30s
1111
allowed_request_paths: '/shows/**,/search/people'
1212
request_query_filters: enabled
13+
14+
- from: https://dummyjson.com/products
15+
name: products
16+
params:
17+
pagination: enabled
18+
pagination_query_params: "skip={offset}&limit={limit}"
19+
pagination_page_size: "30"
20+
pagination_data_pointer: "/products"
21+
pagination_max_pages: "10"

0 commit comments

Comments
 (0)