🔧 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 { 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>> {
|
||||
return await axios.get(`/all`);
|
||||
return await axios.get(`/api/v1/all`);
|
||||
}
|
||||
|
||||
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
|
||||
): 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(
|
||||
template: string
|
||||
): 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[]> {
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@ import { defineConfig } from "vite";
|
|||
import react from "@vitejs/plugin-react-swc";
|
||||
import svgr from "vite-plugin-svgr";
|
||||
const apiRoutes = [
|
||||
"/all",
|
||||
"/predict",
|
||||
"^/validate/*",
|
||||
"^/chat/*",
|
||||
"/version",
|
||||
"/api/v1/all",
|
||||
"/api/v1/predict",
|
||||
"/api/v1/validate/*",
|
||||
"/api/v1/chat/*",
|
||||
"/api/v1/version",
|
||||
"/health",
|
||||
];
|
||||
|
||||
|
|
@ -19,7 +19,7 @@ const proxyTargets = apiRoutes.reduce((proxyObj, route) => {
|
|||
changeOrigin: true,
|
||||
secure: false,
|
||||
ws: true,
|
||||
rewrite: (path) => `/api/v1${path}`,
|
||||
// rewrite: (path) => `/api/v1${path}`,
|
||||
};
|
||||
return proxyObj;
|
||||
}, {});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue