🔧 chore(API): add /api/v1/ prefix to API routes
✨ feat(API): add getVersion function to retrieve the version of the API
The API routes have been updated to include the /api/v1/ prefix to improve semantics and avoid conflicts with other routes. The getVersion function has been added to retrieve the version of the API.
This commit is contained in:
parent
0eaa86c5ca
commit
21440578a7
2 changed files with 39 additions and 11 deletions
|
|
@ -3,24 +3,52 @@ import { APIObjectType, sendAllProps } from "../../types/api/index";
|
||||||
import axios, { AxiosResponse } from "axios";
|
import axios, { AxiosResponse } from "axios";
|
||||||
import { FlowType } from "../../types/flow";
|
import { FlowType } from "../../types/flow";
|
||||||
|
|
||||||
|
// when serving with static files
|
||||||
|
// We need to add /api/v1/ to the url in the axios calls
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves all data from the API.
|
||||||
|
* @returns {Promise<AxiosResponse<APIObjectType>>} A promise that resolves to an AxiosResponse object containing the API data.
|
||||||
|
*/
|
||||||
export async function getAll(): Promise<AxiosResponse<APIObjectType>> {
|
export async function getAll(): Promise<AxiosResponse<APIObjectType>> {
|
||||||
return await axios.get(`/all`);
|
return await axios.get(`/api/v1/all`);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function sendAll(data: sendAllProps) {
|
export async function sendAll(data: sendAllProps) {
|
||||||
return await axios.post(`/predict`, data);
|
return await axios.post(`/api/v1/predict`, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function checkCode(
|
export async function postValidateCode(
|
||||||
code: string
|
code: string
|
||||||
): Promise<AxiosResponse<errorsTypeAPI>> {
|
): Promise<AxiosResponse<errorsTypeAPI>> {
|
||||||
return await axios.post("/validate/code", { code });
|
return await axios.post("/api/v1/validate/code", { code });
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function postValidateNode(
|
||||||
|
nodeId: string,
|
||||||
|
data: any
|
||||||
|
): Promise<AxiosResponse<string>> {
|
||||||
|
return await axios.post(`/api/v1/validate/node/${nodeId}`, { data });
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function checkPrompt(
|
export async function checkPrompt(
|
||||||
template: string
|
template: string
|
||||||
): Promise<AxiosResponse<PromptTypeAPI>> {
|
): Promise<AxiosResponse<PromptTypeAPI>> {
|
||||||
return await axios.post("/validate/prompt", { template });
|
return await axios.post("/api/v1/validate/prompt", { template });
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the version of the API.
|
||||||
|
* @returns {Promise<AxiosResponse<{ version: string }>>} A promise that resolves to an AxiosResponse object containing the API version.
|
||||||
|
* @example
|
||||||
|
* const response = await getVersion();
|
||||||
|
* console.log(response.data.version);
|
||||||
|
* // 0.1.0
|
||||||
|
*/
|
||||||
|
export async function getVersion(): Promise<
|
||||||
|
AxiosResponse<{ version: string }>
|
||||||
|
> {
|
||||||
|
return await axios.get("/api/v1/version");
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getExamples(): Promise<FlowType[]> {
|
export async function getExamples(): Promise<FlowType[]> {
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,11 @@ import { defineConfig } from "vite";
|
||||||
import react from "@vitejs/plugin-react-swc";
|
import react from "@vitejs/plugin-react-swc";
|
||||||
import svgr from "vite-plugin-svgr";
|
import svgr from "vite-plugin-svgr";
|
||||||
const apiRoutes = [
|
const apiRoutes = [
|
||||||
"/all",
|
"/api/v1/all",
|
||||||
"/predict",
|
"/api/v1/predict",
|
||||||
"^/validate/*",
|
"/api/v1/validate/*",
|
||||||
"^/chat/*",
|
"/api/v1/chat/*",
|
||||||
"/version",
|
"/api/v1/version",
|
||||||
"/health",
|
"/health",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
@ -19,7 +19,7 @@ const proxyTargets = apiRoutes.reduce((proxyObj, route) => {
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
secure: false,
|
secure: false,
|
||||||
ws: true,
|
ws: true,
|
||||||
rewrite: (path) => `/api/v1${path}`,
|
// rewrite: (path) => `/api/v1${path}`,
|
||||||
};
|
};
|
||||||
return proxyObj;
|
return proxyObj;
|
||||||
}, {});
|
}, {});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue