Import source: global/src/lib/api
Import the existing local project snapshot. This commit organizes existing files; it does not represent newly developed functionality.
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
// Fetch wrapper for Teknav Global — proxies to same backend as teknav.ir
|
||||
const BASE = '/api/v1';
|
||||
|
||||
async function request(path, options = {}) {
|
||||
const url = `${BASE}${path}`;
|
||||
const res = await fetch(url, {
|
||||
credentials: 'include',
|
||||
headers: { 'Content-Type': 'application/json', ...options.headers },
|
||||
...options,
|
||||
});
|
||||
if (!res.ok) {
|
||||
const err = await res.json().catch(() => ({ error: res.statusText }));
|
||||
throw Object.assign(new Error(err.error || res.statusText), { status: res.status, data: err });
|
||||
}
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export const api = {
|
||||
get: (path) => request(path),
|
||||
post: (path, body) => request(path, { method: 'POST', body: JSON.stringify(body) }),
|
||||
patch: (path, body) => request(path, { method: 'PATCH', body: JSON.stringify(body) }),
|
||||
del: (path) => request(path, { method: 'DELETE' }),
|
||||
};
|
||||
Reference in New Issue
Block a user