REST numeric or string resource identifiers? -


i'm doing research me develop rest api , 1 topic haven't seen discussed in depth anywhere.

if have user in system, better identify user using numeric identifier

/users/1

or using string identifier?

/users/rsmith

i can see hypothetical potential pros , cons each approach, string identifiers more human readable, less discoverable (can't incremented find valid users), , don't require storing numeric id in database (i wouldn't want expose database ids through api). numeric identifiers have no inherent meaning , due that, can guaranteed immutable, whereas string id user might want rename resource, changing resource uri.

is there rest best practice here or best approach vary system system? if latter, there additional pros , cons associated each method?

as know, strictly speaking, there no advantage between both approaches. yes, string identifies may easier people remember, apart that, rest not enforce "pretty" urls (or ids), because of time urls accessed programs following hyperlinks.

thus, human friendly urls should used bootstrapping resources may remembered humans. also, id guessing should not problem because either:

  1. you have restrict access urls based on authentication method, or:
  2. you have use randomized/unguessable urls not "public".

so 1 use? of time, not matter, ids not accessed directly. if have ensure people remember urls reason, try them human-friendly, try avoid resource-name change , apply other means of authentication guessed urls don't access unauthorized places.


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -