Created
July 15, 2021 17:53
-
-
Save sibelius/782bdcefede2f5c134336b15c37dd5c7 to your computer and use it in GitHub Desktop.
Test a request using fetch api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'isomorphic-fetch'; | |
const run = async () => { | |
const payload = { | |
field: 'value' | |
} | |
const options = { | |
method: 'POST', | |
headers: { | |
Accept: 'application/json', | |
'Content-Type': 'application/json', | |
}, | |
body: JSON.stringify(payload), | |
}; | |
const response = await fetch(url, options); | |
const data = await response.json(); | |
console.log({ | |
data, | |
}); | |
}; | |
(async () => { | |
try { | |
await run(); | |
} catch (err) { | |
// eslint-disable-next-line | |
console.log('err: ', err); | |
process.exit(1); | |
} | |
process.exit(0); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
node testRequest.ts