54 lines
925 B
JavaScript
54 lines
925 B
JavaScript
|
|
||
|
export class APIClient {
|
||
|
constructor(baseURL = 'http://localhost:8001/api/v1') {
|
||
|
this.baseURL = baseURL;
|
||
|
this.login = this.login.bind(this);
|
||
|
this.logout = this.logout.bind(this);
|
||
|
this.me = this.me.bind(this);
|
||
|
this.listUsers = this.listUsers.bind(this);
|
||
|
this.listRequests = this.listRequests.bind(this);
|
||
|
}
|
||
|
|
||
|
login(username, password) {
|
||
|
return this._callAPI('/login', { username, password }, 'POST')
|
||
|
}
|
||
|
|
||
|
logout() {
|
||
|
return this._callAPI('/logout')
|
||
|
}
|
||
|
|
||
|
me() {
|
||
|
return this._callAPI('/me')
|
||
|
}
|
||
|
|
||
|
listUsers() {
|
||
|
return this._callAPI('/users')
|
||
|
}
|
||
|
|
||
|
listRequests() {
|
||
|
|
||
|
}
|
||
|
|
||
|
createRequest(request) {
|
||
|
|
||
|
}
|
||
|
|
||
|
updateRequestStatus(reqID, newStatus) {
|
||
|
|
||
|
}
|
||
|
|
||
|
_callAPI(path, body, method='GET') {
|
||
|
return fetch(baseURL + path, {
|
||
|
method,
|
||
|
headers: {
|
||
|
'Content-Type': 'application/json',
|
||
|
},
|
||
|
mode: 'cors',
|
||
|
credentials: true,
|
||
|
body: JSON.stringify(body),
|
||
|
})
|
||
|
.then(res => res.json())
|
||
|
}
|
||
|
|
||
|
}
|