I am building api in rails and I am wondering what is the best way to implement object ids. I don’t want to use database generated id.
This article API with Ruby on Rails: useful tricks | Railsware Blog suggests using guid, but I don’t like the format I would prefer ids similar to parse api. Are there any gems that do this or should I just use securerandom and catch duplicates?
Can anyone point to some good articles or share some tips, best practices about implementing api in rails?
Format aside, a modern UUID saves you the practical trouble of duplicates:
Rails 4 features (decent) support for (type IV) UUID as primary key, so you can just skip to that and avoid integers completely on that table if it’s easier.
@ronin can you clarify why you don’t want to use the database generated id?
Mostly because of the enumeration problem, that some can guess number of records just by looking at id values. Or guess ids of objects from other users and so on.
I don’t necessarilly agree with the priority of your concerns, however if you are then I do recommend you go with the uuid.
It’s been a while, what did you end up going with?