PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 4.9.5
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v4.9.5
4.9.5 4.9.4 4.9.3 4.9.2 4.9.1 4.9.0 4.8.2 4.8.1 4.8.0 4.7.0 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 4.5.1 4.5.0 4.4.1 4.4.0 3.3.4 3.4.0 3.4.1 All 203 releases
betterdocs / react-src / admin / utils / apiFetch.js

apiFetch.js in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 4.9.5, at react-src/admin/utils/apiFetch.js

43 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import apiFetch from "@wordpress/api-fetch";
2 import { sprintf, __ } from "@wordpress/i18n";
3
4 class API {
5 namespace = "/betterdocs";
6 version = "v1";
7 getPath = (path) => {
8 return `${this.namespace}/${this.version}/${path}`;
9 };
10 post = (endpoint, data = {}, args = {}) => {
11 let path = this.getPath(endpoint);
12 args = { path, method: "POST", data, ...args };
13 return apiFetch(args)
14 .then((res) => res)
15 .catch((err) => err);
16 };
17 delete = (endpoint, data = {}, args = {}) => {
18 let path = this.getPath(endpoint);
19 args = { path, method: "DELETE", data, ...args };
20 return apiFetch(args)
21 .then((res) => res)
22 .catch((err) => console.error(err));
23 };
24 get = (endpoint, args = {}) => {
25 let path = this.getPath(endpoint);
26 args = { path, method: "GET", ...args };
27 return apiFetch(args)
28 .then((res) => res)
29 .catch((err) => console.error(err));
30 };
31 useQuery = (search) => {
32 search = search;
33 return new URLSearchParams(search);
34 };
35 getParam = (param, d = null) => {
36 const query = this.useQuery(location.search);
37 return query.get(param) || d;
38 };
39 }
40
41
42 export default new API;
43