Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature(extension-api-caller): add extension-api-caller #277

Merged
merged 7 commits into from
Aug 18, 2023

Conversation

cyyeh
Copy link
Member

@cyyeh cyyeh commented Aug 13, 2023

Description

Add extension-api-caller that allows users to call APIs to get data from the Internet. As of now, it only supports REST APIs.

Issue ticket number

None

Additional Context

@vercel
Copy link

vercel bot commented Aug 13, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
vulcan-sql-document ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 18, 2023 1:17am

@cyyeh cyyeh changed the title add extension-api-caller [WIP]add extension-api-caller Aug 14, 2023
@cyyeh cyyeh changed the title [WIP]add extension-api-caller add extension-api-caller Aug 16, 2023
options = {...options, headers: JSON.parse(args['headers'])}
}

const results = await axios(options);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should handle non status 2xx response with try cache

Copy link
Contributor

@kokokuo kokokuo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beside some suggestion, others LGTM 👍

Comment on lines 15 to 26
const url = args['arg'] && args['arg'] === ':id' ? `${args['url']}/${value}` : args['url'];
const httpMethod = args['method'] || 'get';
let options: any = {
url: url,
method: httpMethod,
params: args['arg'] && args['arg'] !== ':id' ? { [args['arg']]: value } : {},
}
if (args['body']) {
options = {...options, body: JSON.parse(args['body'])}
}
if (args['headers']) {
options = {...options, headers: JSON.parse(args['headers'])}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After discussing with @cyyeh and @onlyjackfrost, we decide to design to pass the header, query, body, and pathfrom thevaluethrough the pipe operator, andrest_apionly pass theurl` keyword argument in the filter function, looks like below

If the URL need to pass the path parameter e.g: http://localhost:3000/users/:id/workspaces/:sqlName , then the SQL will like:

{% set value = { "path": { "id": 1, "sqlName": "ws_1"} }
SELECT {{ value | reset_api(url=http://localhost:3000/users/:id/workspaces/:sqlName) }}

If the URL is http://localhost:3000/users and could query by query string:

{% set value = { "query": { "name": "andy" } }
SELECT {{ value | reset_api(url=http://localhost:3000/users) }}

If the URL is http://localhost:3000/users and could pass the value by header:

{% set value = { "header": { "x-canner-token": "xxxxx" } }
SELECT {{ value | reset_api(url=http://localhost:3000/users) }}

And also update the sample in the test cases

If the URL is http://localhost:3000/users and supports POST method and pass by body:

{% set value = { "body": { name: "andy" } }
SELECT {{ value | reset_api(url=http://localhost:3000/users, method="POST") }}

@cyyeh cyyeh changed the title add extension-api-caller [WIP]add extension-api-caller Aug 16, 2023
@cyyeh cyyeh changed the title [WIP]add extension-api-caller add extension-api-caller Aug 17, 2023
Copy link
Contributor

@kokokuo kokokuo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@cyyeh cyyeh merged commit de4fb81 into Canner:develop Aug 18, 2023
@onlyjackfrost onlyjackfrost changed the title add extension-api-caller Feature(extension-api-caller): add extension-api-caller Aug 18, 2023
@cyyeh cyyeh deleted the add-extension-api-caller branch September 1, 2023 03:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants