Post

Can You Put a Body in REST API DELETE?

Can You Put a Body in REST API DELETE?

Problem

While building the wishlist API at Kakao Tech Campus, I ran into a URL design dilemma for the delete endpoint.

Original design:

1
DELETE /api/wishlist/{id}

Feedback I got: is {id} the wishlist ID or the product ID? It’s ambiguous.


Mentor Feedback

“If the path is /api/wishlist/1, you’d expect 1 to be related to the wishlist—yet your design puts a product-related ID there. Just from looking at the URL, it’s hard to tell which identifier it is.”


Attempt 1: Put in Body

What if I put the product ID in the request body?

1
2
DELETE /api/wishlist
Body: { "productId": 1 }

Turns out this isn’t recommended:

  • HTTP spec allows body in DELETE, but servers may ignore it
  • Some proxies or caches might strip the body
  • It breaks RESTful conventions

Attempt 2: Query Parameter

1
DELETE /api/wishlist?productId=1

This also felt awkward—query parameters on a DELETE just look off.


Final Choice: Clear Path Variable

1
DELETE /api/wishlist/products/{productId}

Or shorter:

1
DELETE /api/wishlist/{productId}

I ended up sticking with path variables, but restructured the URL to clearly express the resource relationship.

/api/wishlist/products/{productId} is a bit long, but the intent—”delete a specific product from the wishlist”—is crystal clear.


Lessons Learned

  • In REST API design, URLs should clearly express resource relationships
  • Body or query params in DELETE requests are generally discouraged
  • Even if the URL gets longer, clarity beats brevity

From Kakao Tech Campus 3rd cohort Gift API clone coding, summarizing mentor feedback.

This post is licensed under CC BY 4.0 by the author.