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 23
is the primary key):
mysite.com/api/v0/sites/23/
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:
mysite.com/api/v0/sites/?domain-name=someothersite.com/
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.
v0
in the examples but it makes sense. :-) – Synthiasyntonic