Curl DELETE Request Example

Deleting with curl is one flag. Reading the answer correctly takes more care, because a successful DELETE often returns nothing at all.

Last updated . How this page is checked.

The command

curl -X DELETE https://httpbin.org/delete

Opens the request console with this request filled in. It is sent from api-tester.com's server rather than from your machine, so it shows what the endpoint returns, not how your own network or curl build behaves.

What the flags do

FlagWhat it does
-X DELETESet the method.
-iShow the status line, the only signal you get from a 204.
-H "Authorization: ..."Nearly every real DELETE endpoint requires credentials.
-d dataAn optional body. Allowed, but not every server reads it.

Reading the response

There are three normal success answers. 204 No Content means deleted, with an empty body, so without -i curl prints nothing and it looks as if nothing happened. 200 OK means deleted, with a body describing the result. 202 Accepted means the deletion was queued and has not happened yet.

Deleting something that is already gone usually returns 404. The end state is the same either way, which is what makes DELETE safe to retry; a script that treats that 404 as a failure will break on its own retries.

curl -i -X DELETE https://api.example.com/users/42 \
  -H "Authorization: Bearer $TOKEN"

# in a script: capture just the status code
code=$(curl -s -o /dev/null -w "%{http_code}" -X DELETE \
  -H "Authorization: Bearer $TOKEN" https://api.example.com/users/42)
[ "$code" = 204 ] || [ "$code" = 404 ] || echo "delete failed: $code"

DELETE with a body

Bulk-delete endpoints sometimes take a list of ids in the body. HTTP permits a body on DELETE but gives it no defined meaning, so support varies: some frameworks ignore it and some proxies strip it. Curl sends it without complaint.

curl -X DELETE https://httpbin.org/delete \
  -H "Content-Type: application/json" \
  -d '{"ids":[41,42,43]}'

Common mistakes

  • There is no undo and no confirmation. Run the same URL as a GET first to be sure which resource it names.
  • A trailing slash can change the target. /users/42 and /users/ are different resources; a variable that expands to nothing turns the first into the second.
  • 405 is not 403. 405 means the URL does not support DELETE; 403 means it does and you are not allowed.

Related curl examples

More under Methods

References

These links leave api-tester.com, which is independent of the projects they point to.

FAQ

How do I send a DELETE request with curl?

Use -X DELETE followed by the URL, for example curl -X DELETE https://httpbin.org/delete, adding -H for any authorization header the API requires.

Can a curl DELETE request have a body?

Yes. Add -d with the data and a Content-Type header. HTTP allows it, but some servers and proxies ignore or drop a DELETE body.

Why does my curl DELETE print nothing?

The server most likely answered 204 No Content, which has an empty body. Add -i to see the status line.