Created
November 28, 2018 15:47
-
-
Save chamatt/243bd126413f86fc28b395d5ff184934 to your computer and use it in GitHub Desktop.
Fetch exemplo de POST
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
| 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