I’m working on a REST API where we have a subscription resources that are identified by natural keys, which is to say, they’re identified in terms of keys from other resources. Ex:
POST /subscriptions/user/123
POST /subscriptions/company/intel
The meaning of this is I want to create a subscription for user 123 or create a subscription for intel. Deleting these subscription “resources” is similar:
DELETE /subscriptions/user/123
DELETE /subscriptions/company/intel
Here’s where I’m unsure of things. I’m creating subscriptions, but I’m identifying the subscriptions in terms of other natural keys: user/123 or company/intel. There is no actual subscription id. Is this an ok way of doing things or should I create a surrogate key for each subscription?
Can you have more than one subscription per user/company? If so, then you will need a key to identify the actual subscription to delete.
If not, then I suppose that would be an OK way of designing your API. I would hope that you generate an error on
POSTif there’s already a subscription — the user should usePUTto make an update, correct?If I were to
GET /subscriptions/, would it be a list of users and companies with subscriptions (/subscriptions/user/123, /subscriptions/company/intel)?Seems reasonable.