Skip to main content

I'm trying to create an extension which makes an external API POST call.

First I tried to make a simple fetch call, but it is failing due to CORS policy:

const response = await fetch('https://api.example.com/data', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({key: 'value'})
});

But then in Block source I have found method unstable_fetchAsync(requestJson).

const requestJson = {
method: 'POST',
url: 'https://api.example.com/data',
headers: [
["Content-Type", "application/json"]
],
body: btoa(JSON.stringify({key: 'value'})),
redirect: 'manual',
integrity: null
}
await unstable_fetchAsync(requestJson);

It's working as expected, but the name is suspicious. Also, this method is not documented anywhere. I'm afraid that after creating the extension, I will not be able to submit it for public usage. 

Is this safe to use unstable_fetchAsync or there is another way to make external API POST calls?

Be the first to reply!

Reply