Created
March 12, 2018 16:09
-
-
Save parzibyte/f173fd3eab7eaad43774a2f193733d4f to your computer and use it in GitHub Desktop.
This file contains 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
<!DOCTYPE html> | |
<html lang="es"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Título</title> | |
<script src="https://cdn.rawgit.com/axios/axios/master/dist/axios.min.js"></script> | |
<script> | |
/* | |
Configurar una constante global | |
para definir, por ejemplo, una URL base. | |
Si esta URL cambia, sólo la cambiamos una vez | |
*/ | |
const HTTP = axios.create({ | |
baseURL: "./servidor.php/" | |
}) | |
HTTP | |
.get("/usuarios") // Es como concatenar './servidor.php/' y 'usuarios' | |
.then(respuesta => { | |
console.log("Petición GET de usuarios terminada. Respuesta: ", respuesta.data); | |
}); | |
let usuario = { | |
nombre: "Luis", | |
correo: "luis@gmail.com", | |
edad: 10, | |
cliente: false, | |
amigos: [ | |
{ | |
nombre: "John Doe", | |
correo: "john.doe@gmail.com", | |
edad: 5 | |
} | |
] | |
}; | |
HTTP | |
.post("/usuario", usuario) | |
.then(respuesta => { | |
console.log("Petición POST de usuario terminada. Respuesta: ", respuesta.data); | |
}); | |
</script> | |
</head> | |
<body> | |
<h1>Peticiones con Axios</h1> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment