I want make a Get Request with axios
get method and chain a post Request if the Promise
is successful
Endpoint is a API the Promise
who should return the Promise
from the Get Request
returns the GET Request Promise
considering this answer calling a async function inside then this should be possibly
why does the post request gets not trough ?
axios.get('https://reqres.in/api/users/')
.then(() => {
data = {
email: 'eve.holt@reqres.in',
password: 'pistol'
}
return data
}).then((data) => {
const postRequest = axios.post('https://reqres.in/api/register', data);
return postRequest
}).then((response) => {
console.log(response)
}).catch((response) => {
console.log(response)
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Http Requests & JavaScript</title>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js">
</script>
</head>
<body>
</body>
</html>