Hallo, ich möchte versuchen, mit fetch die Daten aus einem anderem Server holen. Allerdings möchte ich nicht alles holen, sondern nur bestimmte Arrays/Objekte z.B. nur Barcode und Name (URL im fetch enthalten).
Wisst ihr, wie ich vorgehen musst?
[CODE lang="javascript" title="1. Variante"]const fetch = require('node-fetch');
fetch('https://world.openfoodfacts.org/api/v0/product/%203045140105502.json')
.then(res => res.text())
.then(text => console.log(text))[/CODE]
[CODE lang="javascript" title="2. Variante"]var data = {};
// hier weiterschreiben?
fetch('https://world.openfoodfacts.org/api/v0/product/%203045140105502.json', {
method: 'GET',
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);
});
[/CODE]
Wisst ihr, wie ich vorgehen musst?
[CODE lang="javascript" title="1. Variante"]const fetch = require('node-fetch');
fetch('https://world.openfoodfacts.org/api/v0/product/%203045140105502.json')
.then(res => res.text())
.then(text => console.log(text))[/CODE]
[CODE lang="javascript" title="2. Variante"]var data = {};
// hier weiterschreiben?
fetch('https://world.openfoodfacts.org/api/v0/product/%203045140105502.json', {
method: 'GET',
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);
});
[/CODE]
Zuletzt bearbeitet: