09-16-2022 22:43
09-16-2022 22:43
Here's a lazy way of testing your companion fetch() code:
const subdomain = 'my-subdomain'
const url = `https://${subdomain}.requestcatcher.com/test`
const data = "G'day."
let fetchInit = {method: 'POST', body: data}
fetch(url, fetchInit)
.then(function(response) {
if (response.ok) {
response.text().then(text => console.log(`Server response: OK (${text})`))
} else {
response.text().then(text => console.log(`Server response: not OK (${text})`))
}
})
.catch(function(err) {
console.log(`fetch error (${err}).`)
})
If you're having troubles with fetch(), this can be useful to isolate whether the problem is with your Fitbit (client) code, or with your server.
You can also use request catcher to test the various fetch() capabilities documented in the Fitbit fetch API.
You probably won't be able to use request catcher for more than simple testing; you'll still need to provide your own server for that.