rectangletangle rectangletangle - 1 year ago 176
reST (reStructuredText) Question

Natural keys and RESTful URLs

I have a RESTful API that I'm designing which uses numeric primary keys for all of its resources. However one type of resource has a convenient natural key, which I'd like to be able to use as an optional way to specify the individual resource. For consistencies sake all resources will be accessible via their primary key.

As it stands, I can do this (assuming

is the primary key):

However, I'm wondering if there's an idiomatic way to specify an alternate natural key for a resource.

So far I was thinking of doing something like this:

So an individual site resource would be accessible by both its primary key and a natural key (its domain name). My primary concern is doing this in and idiomatic fashion, seeing as I'd like to make the API as straightforward to use as possible.

Answer Source

In your particular situation, the primary key (integer) can always easily be differentiated from the domain name (string including a period). It seems perfectly valid (and intuitive) to allow both in the same location of the URL:

Documenting it is straightforward too, as each is a unique identifier for a site:{id}
  id: primary key or fully-qualified domain name
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download