Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

lectures/remove?id=${lecture._id}

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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:

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading