diff --git a/src/api/userApi.js b/src/api/userApi.js new file mode 100644 index 0000000..ba07e58 --- /dev/null +++ b/src/api/userApi.js @@ -0,0 +1,35 @@ +// src/api/userApi.js +export default class UserApi { + constructor(token) { + this.baseUrl = 'https://thalos-bff.dream-views.com/api/v1/User'; + this.token = token; + } + + // helper for headers + getHeaders() { + return { + 'accept': 'application/json', + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${this.token}`, + }; + } + + // === GET all users === + async getAllUsers() { + try { + const response = await fetch(`${this.baseUrl}/GetAll`, { + method: 'GET', + headers: this.getHeaders(), + }); + + if (!response.ok) { + throw new Error(`Failed to fetch users: ${response.status}`); + } + + return await response.json(); + } catch (err) { + console.error('Error fetching users:', err); + throw err; + } + } +} \ No newline at end of file