Failed to send DELETE request using apetch api

When I send a delete request to a specific endpoint, for example using httpie from a terminal, for example

http delete http://localhost:8181/admin/applications/uspecs

I get the correct behavior, as in { success: true } as the response body. But when I do

 fetch ( 'http://localhost:8181/admin/applications/uspecs', { method: 'DELETE' } ) .then(res => doSomethingWithResponse()) .catch(err => console.error(err)) 

In JavaScript code, I get

 Fetch API cannot load http://localhost:8181/admin/applications/uspecs. Method DELETE is not allowed by Access-Control-Allow-Methods in preflight response. 

error in the console. What am I missing? I get a valid list of methods on request options.

+7
source share
1 answer

You need to send the Access-Control-Allow-Methods header containing the allowed methods. Your header is currently named methods .

+5
source

All Articles