-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathrequests.js
More file actions
33 lines (29 loc) · 838 Bytes
/
requests.js
File metadata and controls
33 lines (29 loc) · 838 Bytes
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
const axios = require("axios");
const url = "http://localhost:5001/constellations";
axios
.get(url)
.then((response) => {
const result = response.data.filter((constellation) => {
return constellation.starsWithPlanets < 10;
});
console.log(result);
})
.catch((error) => {
console.log(error.message);
});
axios
.post(url, {
name: "Ara",
meaning: "Altar",
starsWithPlanets: 7,
quadrant: "SQ3",
})
.then((response) => {
console.log(response.data);
});
// Since the ID for the newly created constellation
// is randomly generated, yours will look different from
// what is shown here.
const idToDelete = "ctvVRjy";
axios.delete(`${url}/${idToDelete}`);
axios.get(`${url}/${idToDelete}`); // should return a 404 error, since the constellation was deleted in the previous API call