-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.ts
38 lines (34 loc) · 1.12 KB
/
api.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import axios from 'axios'
module.exports = {
// GET all devices from the API
getDevices: function () {
return axios
.get('http://localhost:3000/devices')
.then(res => {
return res.data
})
},
// Make a PUT request to the API to update a device
updateDevice: function (updatedRecord) {
return axios
.put(`http://localhost:3000/devices/${updatedRecord.id}`, {
id: updatedRecord.id,
system_name: updatedRecord.system_name,
hdd_capacity: updatedRecord.hdd_capacity,
type: updatedRecord.type
})
.catch(error => {
console.error('Error updating device via API:')
console.error(error.toJSON())
})
},
// DELETE a device via the API
deleteDevice: function (id) {
return axios
.delete(`http://localhost:3000/devices/${id}`)
.catch(error => {
console.error('Error deleting device via API:')
console.error(error.toJSON())
})
}
}