Browse Source

feat: add axiosRequestMake

pull/1931/head
Wing-Kam Wong 2 years ago
parent
commit
4950331847
  1. 18
      packages/nocodb-sdk/src/lib/Api.ts
  2. 47
      packages/nocodb/src/lib/noco/meta/api/utilApis.ts
  3. 33
      scripts/sdk/swagger.json

18
packages/nocodb-sdk/src/lib/Api.ts

@ -3073,6 +3073,24 @@ export class Api<
...params,
}),
/**
* @description Generic Axios Call
*
* @tags Utils
* @name AxiosRequestMake
* @request POST:/api/v1/db/meta/axiosRequestMake
* @response `200` `object` OK
*/
axiosRequestMake: (data: object, params: RequestParams = {}) =>
this.request<object, any>({
path: `/api/v1/db/meta/axiosRequestMake`,
method: 'POST',
body: data,
type: ContentType.Json,
format: 'json',
...params,
}),
/**
* No description
*

47
packages/nocodb/src/lib/noco/meta/api/utilApis.ts

@ -60,6 +60,52 @@ export async function releaseVersion(_req: Request, res: Response) {
res.json(result);
}
export async function axiosRequestMake(req: Request, res: Response) {
const { apiMeta } = req.body;
if (apiMeta?.body) {
try {
apiMeta.body = JSON.parse(apiMeta.body);
} catch (e) {
console.log(e);
}
}
if (apiMeta?.auth) {
try {
apiMeta.auth = JSON.parse(apiMeta.auth);
} catch (e) {
console.log(e);
}
}
apiMeta.response = {};
const _req = {
params: apiMeta.parameters
? apiMeta.parameters.reduce((paramsObj, param) => {
if (param.name && param.enabled) {
paramsObj[param.name] = param.value;
}
return paramsObj;
}, {})
: {},
url: apiMeta.url,
method: apiMeta.method || 'GET',
data: apiMeta.body || {},
headers: apiMeta.headers
? apiMeta.headers.reduce((headersObj, header) => {
if (header.name && header.enabled) {
headersObj[header.name] = header.value;
}
return headersObj;
}, {})
: {},
responseType: apiMeta.responseType || 'json',
withCredentials: true
};
const data = await require('axios')(_req);
return res.json(data?.data);
}
export default router => {
router.post(
'/api/v1/db/meta/connection/test',
@ -67,4 +113,5 @@ export default router => {
);
router.get('/api/v1/db/meta/nocodb/info', catchError(appInfo));
router.get('/api/v1/db/meta/nocodb/version', catchError(releaseVersion));
router.post('/api/v1/db/meta/axiosRequestMake', catchError(axiosRequestMake));
};

33
scripts/sdk/swagger.json

@ -4800,6 +4800,39 @@
"description": ""
}
},
"/api/v1/db/meta/axiosRequestMake": {
"parameters": [],
"post": {
"summary": "",
"operationId": "utils-axios-request-make",
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {}
}
}
}
}
},
"description": "Generic Axios Call",
"requestBody": {
"content": {
"application/json": {
"schema": {
"type": "object"
}
}
}
},
"tags": [
"Utils"
]
}
},
"/api/v1/db/meta/nocodb/version": {
"parameters": [],
"get": {

Loading…
Cancel
Save