Skip to content

Instantly share code, notes, and snippets.

@ardiesaeidi
Created August 17, 2020 16:44
Show Gist options
  • Save ardiesaeidi/f27682bfc9ef47d5998cd623ef7ba503 to your computer and use it in GitHub Desktop.
Save ardiesaeidi/f27682bfc9ef47d5998cd623ef7ba503 to your computer and use it in GitHub Desktop.
using fetch api to make clientside requests
fetch('/api/v1/clients', {
method: 'post',
headers: {
'accept': 'application/json',
'content-type': 'application/json',
'x-csrf-token': 'bJYS4JDu-mmYxfO4Vrnqb8vruIC8Hh-uAvzk'
},
body: JSON.stringify({ "name": "test" })
}).then(function(res) {
res.json().then(function(data) {
console.log(data);
});
})
fetch('/api/v1/clients', {
method: 'POST',
headers: {
'accept': 'application/json'
},
body: JSON.stringify({ "name": "test" })
}).then(function(res) {
res.json().then(function(data) {
console.log(data);
});
})
fetch('/api/v1/clients', {
method: 'post',
headers: {
'accept': 'application/json',
'content-type': 'application/json',
'x-csrf-token': '6v0vDFuc-lpc3-s2zSXGXoHCJ0qTDA0pyox8',
'host': 'evil.com'
},
body: JSON.stringify({ "name": "test" })
}).then(function(res) {
res.json().then(function(data) {
console.log(data);
});
})
fetch('/api/v1/Clients')
.then(function(res) {
res.json().then(function(data) {
console.log(data);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment