“aller chercher” Réponses codées

aller chercher

const data = { username: 'example' };

fetch('https://example.com/profile', {
  method: 'POST', // or 'PUT'
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify(data),
})
.then(response => response.json())
.then(data => {
  console.log('Success:', data);
})
.catch((error) => {
  console.error('Error:', error);
});
Lively Ladybird

aller chercher

fetch('http://example.com/movies.json')
  .then((response) => {
    return response.json();
  })
  .then((myJson) => {
    console.log(myJson);
  });
Gleaming Gemsbok

aller chercher

//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);
});

//
Creepy Gábor

aller chercher

const options = {method: 'GET', headers: {Accept: 'application/json'}};

fetch('https://api.test.com/data/id', options)
  .then(response => response.json())
  .then(response => console.log(response))
  .catch(err => console.error(err));
ofroog

aller chercher

const fetch = require('node-fetch');

    let response = await fetch(`your url paste here`, {
      headers: {
        Authorization: `Token ${API_TOKEN}`,
        "Content-Type": "application/json",
      },
      body: JSON.stringify(payload),
      method: 'POST',
    });
    const results = await response.json();
    console.log("======> :: results", results);
abhi

aller chercher

var formData = new FormData();
var fileField = document.querySelector("input[type='file']");

formData.append('username', 'abc123');
formData.append('avatar', fileField.files[0]);

fetch('https://example.com/profile/avatar', {
  method: 'PUT',
  body: formData
})
.then(response => response.json())
.catch(error => console.error('Error:', error))
.then(response => console.log('Success:', response));
Panicky Panda

aller chercher

GET /orgs/octokit/repos
Anxious Ant

Réponses similaires à “aller chercher”

Questions similaires à “aller chercher”

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code