Code maintainability fixes
This commit is contained in:
@@ -13,12 +13,12 @@ const headers = () => {
|
||||
};
|
||||
|
||||
export const api = {
|
||||
get: async (endpoint: string) => {
|
||||
get: async <T = any>(endpoint: string): Promise<T> => {
|
||||
const res = await fetch(`${API_URL}${endpoint}`, { headers: headers() });
|
||||
if (!res.ok) throw new Error(await res.text());
|
||||
return res.json();
|
||||
},
|
||||
post: async (endpoint: string, data: any) => {
|
||||
post: async <T = any>(endpoint: string, data: any): Promise<T> => {
|
||||
const res = await fetch(`${API_URL}${endpoint}`, {
|
||||
method: 'POST',
|
||||
headers: headers(),
|
||||
@@ -27,7 +27,7 @@ export const api = {
|
||||
if (!res.ok) throw new Error(await res.text());
|
||||
return res.json();
|
||||
},
|
||||
put: async (endpoint: string, data: any) => {
|
||||
put: async <T = any>(endpoint: string, data: any): Promise<T> => {
|
||||
const res = await fetch(`${API_URL}${endpoint}`, {
|
||||
method: 'PUT',
|
||||
headers: headers(),
|
||||
@@ -36,7 +36,7 @@ export const api = {
|
||||
if (!res.ok) throw new Error(await res.text());
|
||||
return res.json();
|
||||
},
|
||||
delete: async (endpoint: string) => {
|
||||
delete: async <T = any>(endpoint: string): Promise<T> => {
|
||||
const res = await fetch(`${API_URL}${endpoint}`, {
|
||||
method: 'DELETE',
|
||||
headers: headers()
|
||||
@@ -44,7 +44,7 @@ export const api = {
|
||||
if (!res.ok) throw new Error(await res.text());
|
||||
return res.json();
|
||||
},
|
||||
patch: async (endpoint: string, data: any) => {
|
||||
patch: async <T = any>(endpoint: string, data: any): Promise<T> => {
|
||||
const res = await fetch(`${API_URL}${endpoint}`, {
|
||||
method: 'PATCH',
|
||||
headers: headers(),
|
||||
|
||||
Reference in New Issue
Block a user