Reputation: 1287
I would like to design a rest API with delete method which contains optional parameters.I think it is not a recommended way to have body for delete method.Either i need to pass the parameters as a path param/query param.Can i have optional fields in path param/query param?
My resource is as below
DELETE policy/{policy-number}/{entity-type}/endorse-number
Entity type is optional.
Any help appraciated.
Upvotes: 0
Views: 57
Reputation: 130907
The REST architectural style, defined in the chapter 5 of Roy T. Fielding's dissertation, says nothing about what the URLs must be like. It defines a set of constraints that must be followed by the applications that follow such architecture.
On the other hand, the examples of this article written by Martin Fowler explaining a model defined by Leonard Richardson suggest a URL structure that looks friendly and easy to read.
You could use a matrix parameter. Assuming that you want to delete the endorse number for a given policy (filtered by entity type), you could use:
DELETE /policy/{policy-number};entity-type={entity-type}/endorse-number
To delete the endorse number for a given policy, just remove the entity type filter:
DELETE /policy/{policy-number}/endorse-number
Upvotes: 2