0

I am trying to delete resource using id and name, so I have two different methods to delete the resource using id and name. The think I realized later is that this will throw me ambiguous http operation.

example Delete an animal from the database using following operation:

/animal/1 or animal/elephant

I do not believe query parameters is the right answer for this. You are trying to delete a particular resource and I feel path param would be the right answer for it (delete a resource with a sepcific path, query params are mostly used for Getting a resource). However, I am not sure how can I achieve this without getting an exception. Any ideas?

1 Answers1

0

A resource should be identifiable by only one URL, in your case the ID.

Locating the object by other means is a search, aka a query, e.g. by name, even if names are guaranteed to be unique.

So, the following would be good, clear URLs:

/animal/1
/animal?name=elephant
/animal?color=grey

You could also using matrix parameters, e.g. if the tail of an elephant is a resource:

/animal/1/tail
/animal;name=elephant/tail

See URL matrix parameters vs. request parameters.

Andreas
  • 138,167
  • 8
  • 112
  • 195
  • is it "restfully" correct to pass them as query parameters and have some validation around it for either of them to be set? – LifeStartsAtHelloWorld Jan 11 '18 at 00:35
  • @LifeStartsAtHelloWorld Yes. See [REST API Best practices: Where to put parameters?](https://stackoverflow.com/q/4024271/5221149) – Andreas Jan 11 '18 at 04:46