Q:

fetch api template

//fetch api template
const fetchData=(inputs)=>{
fetch('https://example.com/api', {
    method: 'post',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(inputs)
  })
  .then(function(response) {
    return response.json();
  })
  .then(function(data) {
    ChromeSamples.log(data.whatever);
  });
}
1
method: 'POST',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({a: 1, b: 'Textual content'})
1
For get request: https://jsonplaceholder.typicode.com/
For post request: https://reqbin.com/req/zvtstmpb/post-request-example
0

New to Communities?

Join the community