use-http icon indicating copy to clipboard operation
use-http copied to clipboard

Support HTTP 1.1 DELETE with BODY

Open ericlowry opened this issue 4 years ago • 4 comments

Describe the bug Support HTTP 1.1 RFC 7231 method DELETE (which may have a BODY)

Steps to reproduce

const fetcher = useFetch('http://my/api');
fetcher.del('widget', {xyz:"123"});

Observed Behavior the endpoint DELETE method gets invoked, but no body is passed along with request.

Note: fetcher.post('widget',{xyz:"123"}); works as expected

Expected behavior when calling fetcher.del(route,body) the body, the body should be serialized and sent along with the request, just like a post/put/patch etc.

ericlowry avatar Apr 27 '21 22:04 ericlowry

Please submit a codesandbox reproducing the bug because at first glance it seems like I'm doing the same thing with both post and delete.

iamthesiz avatar Apr 28 '21 06:04 iamthesiz

This bug happened to me as well and I think I know what the issue is. After inspecting both a POST and a DELETE request in the network panel I could see that the DELETE request was not sending the correct Content-Type headers.

So for now, adding the headers to the hook works: useFetch({ headers: { "Content-Type": "application/json" } })

hinderson avatar Oct 07 '21 15:10 hinderson

feel free to submit a PR

iamthesiz avatar Oct 08 '21 17:10 iamthesiz

i think DELETE results in different headers

violinchris avatar Jun 15 '22 17:06 violinchris