why I use axios.delete(url) or axios.put() to send request, but when I check request from NetWork in Chrome Dev Tools the Request Method is OPTIONS and Access-Control-Request-Method is DELETE or PUT like this:
This pre-flight request is made by some browsers as a safety measure to ensure that the request being done is trusted by the server. Meaning the server understands that the method, origin and headers being sent on the request are safe to act upon.
To Use Axios Delete request with body and headers In ReactJS You Just need to Use axios. delete{URL,{headers:{},data:{}}} This Structure, Where You can Pass Authorization, and etc Params That you want to pass in your headers, and pass all body params in data{}. Now, You Can Easily Use Delete Request. Thank You.
Prevent sending the post data, if it wont be processed This is the only reason what is valid. Using options request will prevent sending the post data to the server unnecessarily.
DELETE request using axios with async/await This sends the same DELETE request using axios, but this version uses an async function and the await javascript expression to wait for the promises to return (instead of using the promise then() method as above).
DELETE
or PUT
(or other non-simple) requests first send out a preflighted OPTIONS
request to determine if you're allowed to send this request. The request method is given in the Access-Control-Request-Method
header.
See more here https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#Simple_requests
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With