Skip to content

Instantly share code, notes, and snippets.

@devrsantos
Created September 3, 2018 16:12
Show Gist options
  • Save devrsantos/57c0311aacad8ce3a28eefac64233add to your computer and use it in GitHub Desktop.
Save devrsantos/57c0311aacad8ce3a28eefac64233add to your computer and use it in GitHub Desktop.
Exemplo simples de CRUD utilizando Fetch_API
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