Back

send POST request to functions

  • 0
  • Functions
Alex Bourg
16 Apr, 2024, 20:16

Hi, when I send a request using js to my function, the request method changes from POST to OPTIONS. It works as POST on postman, or python script, but not when I use js.. anyone seen this before?

TypeScript
fetch(apiUrl, {
    method: 'POST',
    headers: myHeaders,
    body: JSON.stringify(data),
    redirect: "follow"
    // body: JSON.stringify({
    //     data: JSON.stringify(data), // Data needs to be a string inside the outer JSON payload
    //     async: false
    // })
})

I tried the 2 approaches above..

TL;DR
When sending a POST request from JS to a function, the request method changes to OPTIONS due to browsers making a preflight CORS check. This behavior is expected. You can adjust your server to handle OPTIONS requests or use a proxy to forward the requests.
Steven
16 Apr, 2024, 20:17

Are you making this request from a web app? If so, it's expected. Browsers make an OPTIONS call first to check for CORS

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more