-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathapiCallsWithAxios.js
45 lines (37 loc) · 1.32 KB
/
apiCallsWithAxios.js
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
import axios from "axios";
const getAllEmployees = async () => {
const url = "http://localhost:8080/api/employees";
const { data, status } = await axios.get(url).then((resp) => resp);
return { data, status };
};
const getOneEmployee = async (id) => {
// Templete Literal
const url = `http://localhost:8080/api/employees/${id}`;
const { data, status } = await axios.get(url).then((resp) => resp);
return { data, status };
};
const postOneEmployee = async (body) => {
const url = "http://localhost:8080/api/employees";
const { status, data } = await axios.post(url, body).then((resp) => resp);
return { status, data };
};
const putOneEmployee = async (id, body) => {
const url = `http://localhost:8080/api/employees/${id}`;
const { status, data } = await axios.put(url, body).then((resp) => resp);
return { status, data };
};
const deleteOneEmployee = async (id) => {
const url = `http://localhost:8080/api/employees/${id}`;
const { status } = await axios.delete(url).then((resp) => resp);
return { status };
};
// const result = await getAllEmployees();
// const result = await getOneEmployee(3);
const body = {
firstName: "Emin",
lastName: "Kara",
};
// const result = await postOneEmployee(body);
// const result = await putOneEmployee(5,body);
const result = await deleteOneEmployee(5);
console.log(result);