Skip to content

Commit 8617014

Browse files
authored
[Feature][connector-http] Parameters support placeholder replacement (#9184)
1 parent 564863b commit 8617014

File tree

16 files changed

+1462
-82
lines changed

16 files changed

+1462
-82
lines changed

docs/en/connector-v2/source/Http.md

+152-8
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ They can be downloaded via install-plugin.sh or from the Maven central repositor
5151
| schema.fields | Config | No | - | The schema fields of upstream data |
5252
| json_field | Config | No | - | This parameter helps you configure the schema,so this parameter must be used with schema. |
5353
| pageing | Config | No | - | This parameter is used for paging queries |
54-
| pageing.page_field | String | No | - | This parameter is used to specify the page field name in the request parameter |
54+
| pageing.page_field | String | No | - | This parameter is used to specify the page field name in the request. It can be used in headers, params, or body with placeholders like ${page_field}. |
55+
| pageing.use_placeholder_replacement | Boolean | No | false | If true, use placeholder replacement (${field}) for headers, parameters and body values, otherwise use key-based replacement. |
5556
| pageing.total_page_size | Int | No | - | This parameter is used to control the total number of pages |
5657
| pageing.batch_size | Int | No | - | The batch size returned per request is used to determine whether to continue when the total number of pages is unknown |
5758
| pageing.start_page_number | Int | No | 1 | Specify the page number from which synchronization starts |
@@ -215,7 +216,7 @@ By default, the parameters will be added to the url path.
215216
If you need to keep the old version behavior, please check keep_params_as_form.
216217

217218
### body
218-
The HTTP body is used to carry the actual data in requests or responses, including JSON, form submissions.
219+
The HTTP body is used to carry the actual data in requests or responses, including JSON, form submissions.
219220

220221
The reference format is as follows:
221222
```hocon
@@ -311,7 +312,7 @@ This parameter helps you configure the schema,so this parameter must be used wit
311312
If your data looks something like this:
312313

313314
```json
314-
{
315+
{
315316
"store": {
316317
"book": [
317318
{
@@ -366,14 +367,25 @@ source {
366367
- See this link for task configuration [http_jsonpath_to_assert.conf](../../../../seatunnel-e2e/seatunnel-connector-v2-e2e/connector-http-e2e/src/test/resources/http_jsonpath_to_assert.conf).
367368

368369
### pageing
369-
The current supported pagination type are `PageNumber` and `Cursor`.
370+
The current supported pagination type are `PageNumber` and `Cursor`.
370371
if you need to use pagination, you need to configure `pageing`. the default pagination type is `PageNumber`.
371372

372373

373374
#### 1. PageNumber
374-
When you need to concatenate page param in the URL,then add params.
375-
When you need to set page param to the body,add the key of page param in body.
375+
When using `PageNumber` pagination, you can include page parameters in different parts of your HTTP request:
376+
377+
- **In URL parameters**: Add the page parameter to the `params` section
378+
- **In request body**: Include the page parameter in the `body` JSON
379+
- **In headers**: Add the page parameter to the `headers` section
380+
381+
You can use placeholders like `${page}` with `use_placeholder_replacement = true` to dynamically update these values. The placeholders can be used in various formats:
382+
383+
- As a standalone value: `"${page}"`
384+
- With prefix/suffix: `"10${page}"` or `"page-${page}"`
385+
- As a number without quotes: `${page}` (in JSON body)
386+
- In nested JSON structures: `{"pagination":{"page":${page}}}`
376387

388+
##### Example 1: Using page parameters in body and params
377389

378390
```hocon
379391
source {
@@ -391,6 +403,7 @@ source {
391403
page_type="PageNumber"
392404
total_page_size=20
393405
page_field=page
406+
use_placeholder_replacement=true
394407
#when don't know the total_page_size use batch_size if read size<batch_size finish ,otherwise continue
395408
#batch_size=10
396409
}
@@ -402,9 +415,140 @@ source {
402415
}
403416
}
404417
}
418+
```
419+
420+
##### Example 2: Using page parameters in headers
421+
422+
```hocon
423+
source {
424+
Http {
425+
url = "http://localhost:8080/mock/queryData"
426+
method = "GET"
427+
format = "json"
428+
headers={
429+
Page-Number = "${pageNo}"
430+
Authorization = "Bearer token-123"
431+
}
432+
pageing={
433+
page_field = pageNo
434+
start_page_number = 1
435+
batch_size = 10
436+
use_placeholder_replacement = true
437+
}
438+
schema = {
439+
fields {
440+
name = string
441+
age = string
442+
}
443+
}
444+
}
445+
}
446+
```
447+
448+
##### Example 3: Using key-based replacement (without placeholders)
449+
450+
```hocon
451+
source {
452+
Http {
453+
url = "http://localhost:8080/mock/queryData"
454+
method = "GET"
455+
format = "json"
456+
params={
457+
page = "1"
458+
}
459+
pageing={
460+
page_field = page
461+
start_page_number = 1
462+
batch_size = 10
463+
use_placeholder_replacement = false
464+
}
465+
schema = {
466+
fields {
467+
name = string
468+
age = string
469+
}
470+
}
471+
}
472+
}
473+
```
405474

475+
##### Example 4: Using prefixed page number in headers
406476

407-
```
477+
```hocon
478+
source {
479+
Http {
480+
url = "http://localhost:8080/mock/queryData"
481+
method = "GET"
482+
format = "json"
483+
headers = {
484+
Page-Number = "10${page}" # Will become "105" when page=5
485+
Authorization = "Bearer token-123"
486+
}
487+
pageing = {
488+
page_field = page
489+
start_page_number = 5
490+
batch_size = 10
491+
use_placeholder_replacement = true
492+
}
493+
schema = {
494+
fields {
495+
name = string
496+
age = string
497+
}
498+
}
499+
}
500+
}
501+
```
502+
503+
##### Example 5: Using unquoted page number in body
504+
505+
```hocon
506+
source {
507+
Http {
508+
url = "http://localhost:8080/mock/queryData"
509+
method = "POST"
510+
format = "json"
511+
body = """{"a":${page},"limit":10}""" # Unquoted number
512+
pageing = {
513+
page_field = page
514+
start_page_number = 1
515+
batch_size = 10
516+
use_placeholder_replacement = true
517+
}
518+
schema = {
519+
fields {
520+
name = string
521+
age = string
522+
}
523+
}
524+
}
525+
}
526+
```
527+
528+
##### Example 6: Using nested JSON structure with page parameter
529+
530+
```hocon
531+
source {
532+
Http {
533+
url = "http://localhost:8080/mock/queryData"
534+
method = "POST"
535+
format = "json"
536+
body = """{"pagination":{"page":${page},"size":10},"filters":{"active":true}}""" # Nested structure
537+
pageing = {
538+
page_field = page
539+
start_page_number = 1
540+
total_page_size = 20
541+
use_placeholder_replacement = true
542+
}
543+
schema = {
544+
fields {
545+
name = string
546+
age = string
547+
}
548+
}
549+
}
550+
}
551+
```
408552

409553
#### 2. Cursor
410554
the `pageing.page_type` parameter must be set to `Cursor`.
@@ -444,4 +588,4 @@ source {
444588
445589
## Changelog
446590
447-
<ChangeLog />
591+
<ChangeLog />

0 commit comments

Comments
 (0)