Skip to content

Commit 4cddecc

Browse files
authored
Update README.md
1 parent b3cf7df commit 4cddecc

File tree

1 file changed

+65
-20
lines changed

1 file changed

+65
-20
lines changed

docs/README.md

Lines changed: 65 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,74 @@ This very experimental extension spawns an HTTP Client from within DuckDB resolv
99
- `http_get(url)`
1010
- `http_post(url, headers, params)`
1111

12+
### Examples
1213
#### GET
14+
```sql
15+
D WITH __input AS (
16+
SELECT
17+
http_get(
18+
'https://httpbin.org/delay/0'
19+
) AS data
20+
),
21+
__features AS (
22+
SELECT
23+
unnest( from_json((data::JSON)->'headers', '{"Host": "VARCHAR"}') )
24+
AS features
25+
FROM
26+
__input
27+
)
28+
SELECT
29+
__features.Host AS host,
30+
FROM
31+
__features
32+
;
33+
┌─────────────┐
34+
│ host │
35+
varchar
36+
├─────────────┤
37+
httpbin.org
38+
└─────────────┘
39+
```
40+
41+
#### POST
42+
```sql
43+
WITH __input AS (
44+
SELECT
45+
http_post(
46+
'https://httpbin.org/delay/0',
47+
headers => MAP {
48+
'accept': 'application/json',
49+
}::VARCHAR,
50+
params => MAP {}::VARCHAR
51+
) AS data
52+
),
53+
__features AS (
54+
SELECT
55+
unnest( from_json((data::JSON)->'headers', '{"Host": "VARCHAR"}') )
56+
AS features
57+
FROM
58+
__input
59+
)
60+
SELECT
61+
__features.Host AS host,
62+
FROM
63+
__features
64+
;
65+
┌─────────────┐
66+
│ host │
67+
varchar
68+
├─────────────┤
69+
httpbin.org
70+
└─────────────┘
71+
```
72+
73+
#### Full Example w/ spatial data
74+
This is the original example by @ahuarte47 inspiring this community extension.
75+
1376
```sql
1477
D SET autoinstall_known_extensions=1; SET autoload_known_extensions=1;
78+
D LOAD json; LOAD httpfs; LOAD spatial;
79+
1580
D WITH __input AS (
1681
SELECT
1782
http_get(
@@ -56,23 +121,3 @@ D WITH __input AS (
56121
10 rows 4 columns │
57122
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
58123
```
59-
60-
#### POST (WIP)
61-
```sql
62-
D SELECT
63-
http_post(
64-
'https://some.server',
65-
headers => MAP {
66-
'Content-Type': 'application/json',
67-
}::VARCHAR,
68-
params => MAP {
69-
'limit': 1
70-
}::VARCHAR
71-
)
72-
AS data;
73-
```
74-
75-
76-
#### Acknowledgements
77-
78-
Implementation inspired by [https://github.com/duckdb/duckdb/pull/11548] PR by @ahuarte47

0 commit comments

Comments
 (0)