fetch('https://jsonplaceholder.typicode.com/users/1')
.then(res => res.json())
.then(user => console.log(user))
.catch(err => console.error(err));
fetch('/api/contacts', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({name: 'Marie', email: 'marie@example.com'})
}).then(res => res.json());
fetch('/api/protected', {
headers: {
'Authorization': 'Bearer ' + token,
'Content-Type': 'application/json'
}
});
💡 Pour pratiquer : utilise JSONPlaceholder, ReqRes, ou crée ton propre backend Node.js.