Update api.ts
Browse files- src/lib/constants/api.ts +6 -29
src/lib/constants/api.ts
CHANGED
|
@@ -1,47 +1,24 @@
|
|
| 1 |
-
|
| 2 |
|
| 3 |
-
/
|
| 4 |
-
* Base API URL
|
| 5 |
-
* Update this to your actual backend endpoint
|
| 6 |
-
*/
|
| 7 |
-
export const API_URL = 'https://example.com/api';
|
| 8 |
-
|
| 9 |
-
/**
|
| 10 |
-
* Default timeout for API requests (in milliseconds)
|
| 11 |
-
*/
|
| 12 |
export const TIMEOUT = 5000;
|
| 13 |
|
| 14 |
-
/
|
| 15 |
-
* Default headers for API requests
|
| 16 |
-
*/
|
| 17 |
export const DEFAULT_HEADERS = {
|
| 18 |
'Content-Type': 'application/json',
|
| 19 |
Accept: 'application/json',
|
| 20 |
};
|
| 21 |
|
| 22 |
-
/
|
| 23 |
-
* Helper to build full endpoint URLs
|
| 24 |
-
* @param path string endpoint path, e.g., 'users/list'
|
| 25 |
-
* @returns full URL string
|
| 26 |
-
*/
|
| 27 |
export const buildApiUrl = (path: string) => {
|
| 28 |
-
// Ensure no double slashes
|
| 29 |
const trimmedPath = path.startsWith('/') ? path.slice(1) : path;
|
| 30 |
-
return `${
|
| 31 |
};
|
| 32 |
|
| 33 |
-
/
|
| 34 |
-
* Example API endpoints
|
| 35 |
-
*/
|
| 36 |
export const ENDPOINTS = {
|
| 37 |
USERS: 'users',
|
| 38 |
POSTS: 'posts',
|
| 39 |
AUTH_LOGIN: 'auth/login',
|
| 40 |
AUTH_REGISTER: 'auth/register',
|
| 41 |
};
|
| 42 |
-
|
| 43 |
-
/**
|
| 44 |
-
* Example usage:
|
| 45 |
-
* import { buildApiUrl, ENDPOINTS } from '@/lib/constants/api';
|
| 46 |
-
* const url = buildApiUrl(ENDPOINTS.USERS); // https://example.com/api/users
|
| 47 |
-
*/
|
|
|
|
| 1 |
+
export const API_BASE_URL = 'https://example.com/api'; // Base URL for your API
|
| 2 |
|
| 3 |
+
// Default request timeout in milliseconds
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
export const TIMEOUT = 5000;
|
| 5 |
|
| 6 |
+
// Default headers for API requests
|
|
|
|
|
|
|
| 7 |
export const DEFAULT_HEADERS = {
|
| 8 |
'Content-Type': 'application/json',
|
| 9 |
Accept: 'application/json',
|
| 10 |
};
|
| 11 |
|
| 12 |
+
// Helper to build full API URLs
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
export const buildApiUrl = (path: string) => {
|
|
|
|
| 14 |
const trimmedPath = path.startsWith('/') ? path.slice(1) : path;
|
| 15 |
+
return `${API_BASE_URL}/${trimmedPath}`;
|
| 16 |
};
|
| 17 |
|
| 18 |
+
// Common API endpoints
|
|
|
|
|
|
|
| 19 |
export const ENDPOINTS = {
|
| 20 |
USERS: 'users',
|
| 21 |
POSTS: 'posts',
|
| 22 |
AUTH_LOGIN: 'auth/login',
|
| 23 |
AUTH_REGISTER: 'auth/register',
|
| 24 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|