use-http
use-http copied to clipboard
Support HTTP 1.1 DELETE with BODY
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.
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.
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" } })
feel free to submit a PR
i think DELETE results in different headers