Last active
May 26, 2022 19:08
-
-
Save JonEast87/822ab711d6b599e3a163dbf75cb52b14 to your computer and use it in GitHub Desktop.
starter-constellations-server/requests-in-javascript/request.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const axios = require('axios') | |
const BASE_URL = "http://localhost:5000"; | |
// function getAllNames() { | |
// return axios.get(BASE_URL + '/constellations').then((response) => { | |
// const constellations = response.data | |
// const constellationNames = constellations.map(constellation => constellation.name) | |
// console.log(constellationNames) | |
// }) | |
// } | |
// function getConstellationsByQuadrant(quadrant) { | |
// return axios.get(BASE_URL + '/constellations').then((response) => { | |
// const constellations = response.data | |
// const constellationInQuad = constellations.filter(constellation => constellation.quadrant === quadrant) | |
// console.log(constellationInQuad) | |
// }) | |
// } | |
axios | |
.get(url) | |
.then((response) => { | |
console.log(response.status) | |
console.log(response.statusText) | |
console.log(response.data) | |
}) | |
.catch((error) => { | |
console.log(error.message) | |
}) | |
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) | |
}) | |
axios.delete('http://localhost:5000/constellations/tETVgH6') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment