Skip to content

Instantly share code, notes, and snippets.

@chamatt
Created November 28, 2018 15:47
Show Gist options
  • Select an option

  • Save chamatt/243bd126413f86fc28b395d5ff184934 to your computer and use it in GitHub Desktop.

Select an option

Save chamatt/243bd126413f86fc28b395d5ff184934 to your computer and use it in GitHub Desktop.
Fetch exemplo de POST
fetch("https://jsonplaceholder.typicode.com/posts", {
method: "POST",
body: JSON.stringify({
/* Transforma objeto em JSON */
title: "titulo",
body: "corpo do texto",
userId: 1
}),
headers: {
"Content-type": "application/json; charset=UTF-8" // Especifica que será enviado um JSON
}
})
.then(resposta => resposta.json()) //Transforma em objeto javascript
.then(json => FuncaoQueSeraExecutada(json));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment