Ajout APIClient
This commit is contained in:
53
frontend/src/services/api-client.service.js
Normal file
53
frontend/src/services/api-client.service.js
Normal file
@ -0,0 +1,53 @@
|
||||
|
||||
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())
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user