Replies: 2 comments 6 replies
-
The formdata method wasn't implemented in v2.x Are there any reasons for why you can't use async import? It works from commonjs as well |
Beta Was this translation helpful? Give feedback.
-
Hi Jimmy, thanks for bringing me back on road! I managed to import node-fetch v3 using on commonjs project and make a wrapper for it like so: exports.fetch = async function (url, init) {
const {default: fetch} = await import("node-fetch");
return await fetch(url, init);
}; However, when I try to make a POST request, the fetch() function still performs a GET request. So for example if I execute this piece of code I receive a 200 status code, even though a 405 Method not allowed would be expected: await fetch('https://www.google.com', {
method: 'POST',
body: JSON.stringify({"value":"test"}),
headers: { 'Content-Type': 'application/json' }
}); I double-checked it a gazillion times but I can't see what I am missing. It looks like the |
Beta Was this translation helpful? Give feedback.
-
I am making a POST request to a server that responds with multiple files in multipart/form-data response.
The documentation states that:
fetch comes with methods to parse multipart/form-data payloads as well as x-www-form-urlencoded bodies using .formData() this comes from the idea that Service Worker can intercept such messages before it's sent to the server to alter them. This is useful for anybody building a server so you can use it to parse & consume payloads.
However, the
response.formData()
throws an error sayingresponse.formData is not a function
. Am I doing something wrong, or is this no longer supported? Here is my code:I am using
node-fetch@2 (v2.6.7)
since I cannot use imports in my environment.Beta Was this translation helpful? Give feedback.
All reactions