-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Add support for querying a JSON REST API via the httpfs
extension.
You can see this in action here, https://motherduck.com/blog/duckdb-110-hidden-gems/.
1. Custom HTTP headers: your database can do API call
The DuckDB extension mechanism is powerful. Most of them are pre-loaded in the background, and you can't see the magic happening. In a previous [blog post](https://motherduck.com/blog/getting-started-gis-duckdb/), I show how we could query an API with a single line statement and return it as a DuckDB table :
CREATE TABLE poi_france AS SELECT * FROM read_json_auto('https://my-endpoint/api')
What is happening here :
The httpfs extension is loaded to get the data from an HTTP endpoint.
read_json_auto will parse directly the JSON response in a table
But what if our API is not public and requires authentication and other headers?
This is where the new HTTP headers come into play. You can now create http secret.
CREATE SECRET http (
TYPE HTTP,
EXTRA_HTTP_HEADERS MAP {
'Authorization': 'Bearer sk_test_VePHdqKTYQjKNInc7u56JBrQ'
}
);
select unnest(data) as customers
from read_json('https://api.stripe.com/v1/customers');
Snippet courtesy of [Archie](https://x.com/archieemwood) on [duckdbsnippets.com](https://motherduck.com/blog/duckdb-110-hidden-gems/duckdbsnippet.com).
Metadata
Metadata
Assignees
Labels
No labels