Is it bad practice to include id of object i want to delete in url query?


Im wondering if its bad idea for me to send DELETE Request on server endpoint


I am aware that DELETE Requests shouldn’t include req.body.

Does it matter if i pass information via params or query? or is there perhaps better way to sending info as delete request in order to delete some info from db?

Feels like just matter of semantics.

Thanks for answers in advance.

>Solution :

In general, if you have a RESTful API, and you want to refer to a resource you use URL parameters as you want to identify that single resource.

So you would have something like

DELETE /lectures/:lectureId

As it’s a single resource of lectures.

However, you may want to delete multiple resources and in that case, it is a common practice to use query parameters

DELETE lectures?id=LECTURE_1&id=LECTURE_2&id=LECTURE_3...

So the "best practice" that you might be missing here is that you should use nouns instead of verbs in endpoints as you are dealing with resources:

Unless you design your API in a way that you trigger a deletion task/process by calling this endpoint then you can challenge this recommendations.

See more:

Leave a ReplyCancel reply