-
Notifications
You must be signed in to change notification settings - Fork 32
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
options = {...options, headers: JSON.parse(args['headers'])} | ||
} | ||
|
||
const results = await axios(options); |
There was a problem hiding this comment.
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
There was a problem hiding this 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 👍
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'])} |
There was a problem hiding this comment.
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 the
valuethrough the pipe operator, and
rest_apionly pass the
url` 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") }}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
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