-
Notifications
You must be signed in to change notification settings - Fork 0
/
async_network.mjs
55 lines (54 loc) · 1.21 KB
/
async_network.mjs
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
export const axiosInstance = axios.create({
baseURL: 'https://crudcrud.com/api/601da0984f0748d7b401e834f4fbe758'
})
export async function postItem(body){
try{
let response = await axiosInstance.post('/items',body)
if (response.status<300){
return response
}
}catch(error){
return error
}
}
export async function getItems(){
try{
let response = await axiosInstance.get('/items')
if (response.status==200){
let data = await response.data
return data;
}
else{
throw(Error)
}
}catch(e){
return e
}
}
export async function getBody(id){
try{
let response = await axiosInstance.get(`/items/${id}`)
if (response.status==200){
let data = response.data
return data;
}
else{
throw(error)
}
}catch(e){
return e
}
}
export async function putItem(id,body){
try{
let response = await axiosInstance.put(`/items/${id}`,body)
if (response.status<300){
return response;
}
else{
throw(Error)
}
}catch(e){
return e;
}
}