fetch('https://reqres.in/api/users/2', { method: "PUT", headers: { 'Content-type': 'application/json' }, body: JSON.stringify( { name: "Capitain Anonymous"} ) }) .then(res => { if (res.ok) { console.log("HTTP request successful") } else { console.log("HTTP request unsuccessful") } return res }) .then(res => res.json()) .then(data => console.log(data)) .catch(error => console.log(error))
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter