Please consider the following example (common in SaaS applications):
This is a SaaS that deals with Widgets.
- You have an Account, that you authenticate via an API key. Each API key authenticates only one Account.
- You have several Widgets under your Account. A Widget belongs to only one Account and can't be transferred to other Accounts.
The URL representation of a widget can be:
https://api.domain.com/v0/accounts/{accountId}/widgets/{widgetId}https://api.domain.com/v0/widgets/{widgetId}
The difference is that route 1 makes has the accountId explicit and route 2 has it implicit (in the authentication via the API key).
Examples
In the wild there seems to be examples for both alternatives:
For example, Twilio API makes the accountId explicit. To make an outbound call:
curl -X POST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXX/Calls.json \ --data-urlencode "Url=http://demo.twilio.com/docs/voice.xml" \ --data-urlencode "From=+15010000000" \ --data-urlencode "To=+12300000000" \ -u ACXXXXXXXXXXXXXXXXXXX:your_auth_token and Stripe API has the accountId implicit. For example, to retrive your balance:
curl https://api.stripe.com/v1/balance \ -u sk_test_BQokikJOvBiI2HlWgH4olfQ2: What are the trade-offs to both alternatives (explicit and implicit)?