Created
September 3, 2018 16:12
-
-
Save devrsantos/57c0311aacad8ce3a28eefac64233add to your computer and use it in GitHub Desktop.
Exemplo simples de CRUD utilizando Fetch_API
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
const url = ''; | |
const listar = () => { | |
fetch(url).then(function(response){ | |
response.json().then(function(result){ | |
for (var key in result) { | |
console.log(result[key].nome); | |
} | |
}) | |
}); | |
}; | |
const adicionar = () => { | |
fetch(url,{ | |
method: "post", | |
headers: { | |
'Accept': 'application/json', | |
'Content-Type': 'application/json' | |
}, | |
body: JSON.stringify( | |
{ | |
nome:'Cadastrar' | |
} | |
) | |
} | |
) | |
}; | |
const deletar = () => { | |
fetch(url+'/'+ 4, {method:'delete'}).then(response => response.json()); | |
}; | |
const atualizar = () => { | |
fetch(url + '/' + 3,{ | |
method:'put', | |
headers: { | |
'Accept': 'application/json', | |
'Content-Type': 'application/json' | |
}, | |
body: JSON.stringify({ | |
nome:'Atualizar' | |
}) | |
}) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment