Skip to content

Commit 5a0eb4a

Browse files
committed
add extension-api-caller doc
1 parent 91a542f commit 5a0eb4a

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# The API Extension
2+
3+
This extension allows you to call RESTful APIs to other sources, and you can either request, update, or even delete resources to other sources!
4+
5+
## Installation
6+
7+
We need to install an additional package in order to call RESTful APIs:
8+
9+
1. Install package(If you have VulcanSQL in the binary version, you can skip this step)
10+
11+
```bash
12+
npm i @vulcan-sql/extension-api-caller
13+
```
14+
2. Setup `vulcan.yaml`
15+
16+
```yaml
17+
extensions:
18+
api: '@vulcan-sql/extension-api-caller' # add this line
19+
```
20+
21+
## Using the API extension
22+
23+
The minimum example
24+
25+
```sql
26+
SELECT {{ {} | rest_api(url='https://dummyjson.com/products/1') }}
27+
```
28+
29+
To pass the path parameters
30+
31+
```sql
32+
{% set a_variable_you_can_define = { "path": { "id": 1 } } %}
33+
SELECT {{ a_variable_you_can_define | rest_api(url='https://dummyjson.com/products/:id') }}
34+
```
35+
36+
To pass the query parameters
37+
38+
```sql
39+
{% set a_variable_you_can_define = { "query": { "q": "phone" } } %}
40+
SELECT {{ a_variable_you_can_define | rest_api(url='https://dummyjson.com/products/search') }}
41+
```
42+
43+
To issue the POST request
44+
45+
```sql
46+
{% set a_variable_you_can_define = { "body": { "title": "BMW Pencil" } } %}
47+
SELECT {{ a_variable_you_can_define | rest_api(url='https://dummyjson.com/products/add', method='POST') }}
48+
```
49+
50+
To pass the headers and multiple fields
51+
52+
```sql
53+
{% set a_variable_you_can_define = { "headers": { "Content-Type": "application/json" }, "body": { "title": "BMW Pencil" } } %}
54+
SELECT {{ a_variable_you_can_define | rest_api(url='https://dummyjson.com/products/add', method='POST') }}
55+
```
56+
57+
## Examples
58+
59+
You can check out this [restapi-caller](https://github.com/Canner/vulcan-sql-examples/tree/main/restapi-caller) example for further details!
60+

packages/doc/sidebars.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ const sidebars = {
182182
},
183183
]
184184
},
185+
{
186+
type: 'doc',
187+
label: 'API',
188+
id: 'extensions/api',
189+
},
185190
// {
186191
// type: 'category',
187192
// label: 'Overview',

0 commit comments

Comments
 (0)