skip to Main Content

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


  1. Using objectId in url can have 2 problems:

    1. It is not good practice to make objectId public. I personally don’t believe it’s a security risk, but it might look unprofessional.
    2. There is also the practical part that objectId is usually quite long and does not make sense to a person, so it does not look really pretty, like if you used for example a name of the product.

    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.

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search