Technology Blog Posts by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
wilbertsison
Active Participant
2,454
This is for those times when a single instance of an API call needs to be tested. Sometimes, API testing tools are not available or extensions to browsers are not permitted in the environment. In some instances, this neat little code below can help in a pinch. It can be executed in the console of Chrome or Edge Developer Tools which is  generally available.
fetch('https://myapiurl.com/post', {
method: 'POST',
body: JSON.stringify({
examplefield1: 'zzz',
examplefield2: 'yyy',
}),
headers: {
'Content-type': 'application/json; charset=UTF-8'
}
})
.then(res => res.json())
.then(console.log)

 

credit to the good people in Stack Overflow : Making HTTP Requests using Chrome Developer tools - Stack Overflow