HTTP Delete Method from Browser and curl

Friday, March 10th 2023

Q: How do I invoke an HTTP DELETE method from Webkit Inspector's JavaScript console in Chrome?

Typically it is more convenient to do HTTP DELETEs via curl on the command line or use a dedicated tool like Postman.

To invoke an HTTP DELETE method from Webkit Inspector's JavaScript console in Chrome, you can use the fetch() function to make the HTTP request.

Here's an example of how to use fetch() to make a DELETE request:

fetch('http://example.com/api/resource/123', { method: 'DELETE', }) .then(response => { console.log('Success:', response.status); }) .catch((error) => { console.error('Error:', error); });

In the above example, replace http://example.com/api/resource/123 with the URL of the resource you want to delete. This code will make a DELETE request to that URL and log the response status code to the console.

Note that the Webkit Inspector's JavaScript console can only make HTTP requests to the same domain that the webpage is hosted on, due to security restrictions. If you need to make a request to a different domain, you may need to use a proxy or CORS.


Q: How do I invoke HTTP DELETE from curl?

To invoke an HTTP DELETE request via curl on the command line with provided credentials, you can use the -X DELETE flag to specify the HTTP method and the -u flag to specify the username and password for HTTP basic authentication.

Here's an example of how to use curl to make an HTTP DELETE request with credentials:

curl -X DELETE -u username:password http://example.com/api/resource/123

In the above example, replace username and password with the appropriate credentials for HTTP basic authentication, and replace http://example.com/api/resource/123 with the URL of the resource you want to delete.

Note that HTTP basic authentication sends the username and password in clear text, which is not secure. If you need to use a more secure authentication method, you may need to use a different tool or library that supports that method.