Answers for "fetch with parameters"

35

js fetch 'post' json

//Obj of data to send in future like a dummyDb
const data = { username: 'example' };

//POST request with body equal on data in JSON format
fetch('https://example.com/profile', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify(data),
})
.then((response) => response.json())
//Then with the data from the response in JSON...
.then((data) => {
  console.log('Success:', data);
})
//Then with the error genereted...
.catch((error) => {
  console.error('Error:', error);
});

//																		Yeah
Posted by: Guest on March-28-2020
2

fetch and then javascript send parameters

const url = 'https://randomuser.me/api';
// The data we are going to send in our request
let data = {
    name: 'Sara'
}
// The parameters we are gonna pass to the fetch function
let fetchData = { 
    method: 'POST', 
    body: data,
    headers: new Headers()
}
fetch(url, fetchData)
.then(function() {
    // Handle response you get from the server
});
Posted by: Guest on September-16-2020
1

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);
  });
}
Posted by: Guest on August-25-2020

Code answers related to "fetch with parameters"

Code answers related to "Javascript"

Browse Popular Code Answers by Language