I’m developing a recipe sharing web app using MERN stack, and i was planning to use this kind of url for showing the recipes info
../recipe/:recipeName/:id
I wanted to know if it is a bad practice to use Mongodb auto generated id in the url or if i should generate a separated public id. The project is for my portfolio and I prefer to avoid all kinds of bad practices so as not to scare away recruiters.
Thanks in advance!
2
Answers
Using objectId in url can have 2 problems:
Honestly I believe it does not really matter, unless you wanna share the link somewhere, where the format ../recipe/:recipeName/:objectName would be Probably better.
What you are describing in your example is called the RESTful service URLs and is perfectly fine for designing an API or a Web App.
Be careful with your URL Depth as best practice is to limit it to
resource/identifier/resource
and any deeper than that suggests a review of your design.Using the
ObjectId
auto-generated by mongodb is an excellent identifier candidate for uniquely identifying your resources in the database. Just do not expose any sensitive information in the url and make sure you have authentication and authorisation to protect your routes, especially ones that mutate the data.