@@ -18,7 +18,7 @@ This wrapper allows you to query any REST API endpoint as a PostgreSQL foreign t
1818
1919| Version | Wasm Package URL | Checksum | Required Wrappers Version |
2020| ------- | ---------------- | -------- | ------------------------- |
21- | 0.1.4 | ` https://github.com/supabase/wrappers/releases/download/wasm_openapi_fdw_v0.1.4/openapi_fdw.wasm ` | ` TBD ` | >=0.5.0 |
21+ | 0.1.4 | ` https://github.com/supabase/wrappers/releases/download/wasm_openapi_fdw_v0.1.4/openapi_fdw.wasm ` | ` dd434f8565b060b181d1e69e1e4d5c8b9c3ac5ca444056d3c2fb939038d308fe ` | >=0.5.0 |
2222
2323## Preparation
2424
@@ -115,7 +115,7 @@ We need to provide Postgres with the credentials to access the API and any addit
115115We recommend creating a schema to hold all the foreign tables:
116116
117117``` sql
118- create schema if not exists api ;
118+ create schema if not exists openapi ;
119119```
120120
121121## Creating Foreign Tables
@@ -354,48 +354,45 @@ For APIs with very strict rate limits, consider using materialized views to cach
354354### Basic Query
355355
356356``` sql
357- create foreign table openapi . users (
358- id text ,
359- name text ,
360- email text ,
361- attrs jsonb
362- )
363- server my_api_server
364- options (
365- endpoint ' /users ' ,
366- rowid_column ' id '
367- );
357+ -- Create a foreign server connecting to the Weather.gov API
358+ create server openapi_server
359+ foreign data wrapper wasm_wrapper
360+ options (
361+ fdw_package_url ' https://github.com/supabase/wrappers/releases/download/wasm_openapi_fdw_v0.1.4/openapi_fdw.wasm ' ,
362+ fdw_package_name ' supabase:openapi-fdw ' ,
363+ fdw_package_version ' 0.1.4 ' ,
364+ fdw_package_checksum ' dd434f8565b060b181d1e69e1e4d5c8b9c3ac5ca444056d3c2fb939038d308fe ' ,
365+ base_url ' https://api.weather.gov ' ,
366+ spec_url ' https://api.weather.gov/openapi.json '
367+ );
368368
369- -- List all users
370- select id, name, email from openapi . users ;
369+ -- Create a schema to hold the imported foreign tables
370+ create schema if not exists openapi;
371371
372- -- Get a specific user
373- select * from openapi .users where id = ' user-123' ;
372+ -- Auto-import all API endpoints as foreign tables based on the OpenAPI spec
373+ import foreign schema openapi from server openapi_server into openapi;
374+
375+ -- Query the stations endpoint to get weather station data
376+ select * from openapi .stations limit 5 ;
374377```
375378
376379### Nested Resources
377380
378381``` sql
379- create foreign table openapi .user_orders (
380- user_id text ,
382+ -- Create a foreign table for a parameterized endpoint with {zone_id} path parameter
383+ create foreign table openapi .zone_stations (
384+ zone_id text ,
381385 id text ,
382- total numeric ,
383- status text ,
384- created_at timestamptz ,
386+ type text ,
385387 attrs jsonb
386- )
387- server my_api_server
388+ ) server openapi_server
388389options (
389- endpoint ' /users/{user_id}/orders ' ,
390+ endpoint ' /zones/forecast/{zone_id}/stations ' ,
390391 rowid_column ' id'
391392);
392393
393- -- Get orders for a specific user
394- select * from openapi .user_orders where user_id = ' user-123' ;
395-
396- -- Get a specific order
397- select * from openapi .user_orders
398- where user_id = ' user-123' and id = ' order-456' ;
394+ -- Query stations for Alaska zone AKZ317 - generates GET /zones/forecast/AKZ317/stations
395+ select id, type from openapi .zone_stations where zone_id = ' AKZ317' ;
399396```
400397
401398### Custom Headers
0 commit comments