Skip to content

Instantly share code, notes, and snippets.

@sibelius
Created July 15, 2021 17:53
Show Gist options
  • Save sibelius/782bdcefede2f5c134336b15c37dd5c7 to your computer and use it in GitHub Desktop.
Save sibelius/782bdcefede2f5c134336b15c37dd5c7 to your computer and use it in GitHub Desktop.
Test a request using fetch api
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);
})();
@sibelius
Copy link
Author

node testRequest.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment