Migrating from Request do Fetch

Hello! Very excited for V8! Amazing job as always.

But now I’m struggling on how to migrate my code, especially from request to fetch.

Does anyone have a good example on how to do it?

Thanks!

You can just follow Fetch docs Fetch API - Web APIs | MDN

Hi,

i’m using PHP in my backend and was wondering why there the $_POST Data appeared to be empty and this gave me the solution:

There were two Options:

Either send the Request as Form Data

var formData = new FormData();

for(var item in data) {
   formData.append(item, data[item]);
}

Or change the Backend to get the body from the fetch as a JSON

$_POST = json_decode(file_get_contents('php://input'), true);

And the Request would look like this

 var response = await fetch(url, {
   method: "POST",
   body: JSON.stringify(data)
});

return response.json();