December 2019
Intermediate to advanced
598 pages
12h 21m
English
fetch('http://localhost:17525/api/person', { method: 'post', headers: { 'Content-Type': 'application/json', }, body: { firstName: 'Fred' surname: 'Smith' }})
The problem is that the fetch function expects the body to be in string format. The corrected call is as follows:
fetch('http://localhost:17525/api/person', { method: 'post', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ firstName: 'Fred' surname: 'Smith' })})
fetch('http://localhost:17525/api/person/1') .then(res => { console.log('firstName', res.body.firstName); })
Read now
Unlock full access