Skip to content

Commit

Permalink
session 28: axios
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeeppy committed Apr 30, 2023
1 parent 99053ed commit 7cb2f64
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
30 changes: 30 additions & 0 deletions session28/axios-get/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" />
<link rel="stylesheet" href="style.css" />
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
</head>
<body>
<div class="container">

<div class="row justify-content-center">

<div class="col-md-8">
<h1 class="text-center mt-5">Bitcoin Price</h1>

<div id="price" class="text-center">
<span id="price_label">xxxx.xx</span>
</div>
</div>

</div>

</div>
<script src="script.js"></script>
</body>
</html>
13 changes: 13 additions & 0 deletions session28/axios-get/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const url = 'https://blockchain.info/ticker';

async function recupererPrix() {
axios.get(url)
.then(function(donnees) {
document.querySelector("#price_label").textContent = donnees.data.EUR.last;
})
.catch(function(erreur) {
alert('Un problème est survenu');
})
}

setInterval(recupererPrix, 1000);
7 changes: 7 additions & 0 deletions session28/axios-get/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
h1 {
color: #272343;
}

#price {
font-size: 4em;
}
17 changes: 17 additions & 0 deletions session28/axios-post/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const url = 'https://lesoublisdelinfo.com/api.php';

const axiosInstance = axios.create({
headers: {
'Content-Type': 'applicaiton/x-www-form-urlencoded'
}
});

axiosInstance.post(url, new URLSearchParams({
prenom: 'Steve'
}))
.then(function(donnees) {
console.log(donnees);
})
.catch(function(erreur) {
console.log(erreur);
})

0 comments on commit 7cb2f64

Please sign in to comment.