Created
January 18, 2019 15:47
-
-
Save yickson/954fdbe172ac9d0f4b45ee9e4ee8fa3b to your computer and use it in GitHub Desktop.
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
| /* | |
| * Ejemplo de código de como funciona la API de Fecth para hacer peticiones mediante POST | |
| * Los parametros son convertidos a Json mediante Stringify | |
| * La primera promesa devuelve los datos los cuales son parseado a un Json | |
| * La segunda promesa devuelve la respuesta de la petición HTTP | |
| * Caso de un error lo captura el Catch de Fetch | |
| */ | |
| fetch('http://UrlDeTuApi.cl/api/login', { | |
| method: 'POST', | |
| headers: { | |
| 'Content-Type': 'application/json' | |
| }, | |
| body: JSON.stringify({"email":"admin@gmail.com", "password":"123456", "provider":"users"}), | |
| }) | |
| .then(function(response) { | |
| console.log('response =', response); | |
| return response.json(); | |
| }) | |
| .then(function(data) { | |
| console.log(data); | |
| }) | |
| .catch(function(err) { | |
| console.error(err); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment