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!
What you are describing in your example is called 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 so you can use them in the url. 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.