I'm currently investigating the possible benefits of a proper REST API, but am uncertain if I understand the concept correctly.
For example, if I wanted to get the third ordered item associated with a specific payment, in a traditional level 2 API I would
GET myapi.com/payments/123/items/3
However in a REST API I am supposed to not need any out of band information except for the entry point. So I cannot make any assumptions about the URL structure or available resources.
To achieve the same functionality I would need to
Hit root -- GET myapi.com
Follow link -- GET myapi.com/payments/123
Follow link -- GET myapi.com/payments/123/items/3
Is this correct? Do I always have to start at the root?
As long as I do not enforce opaque URLs, I guess my clients would still be able to access the required information directly and use the response links to navigate from there on. But in this case they would break with API changes, e.g. payments --> mypayments, as their entry point of choice would have moved.
If the traversal of links relative to root is the only option to avoid client breakage, doesn't that affect performance a lot? After all I'm doing three times as many requests for an request as simple as this example. And that is if I included links to individual payments and items on the root and payment endpoints respectively. If I didn't it would probably look more like this
GET myapi.com -- {users, payments}
GET myapi.com/payments -- {payments/1, payments/2, ..., payments/n}
GET myapi.com/payments/123 -- {payments/123/items, payments/123/somethingidontneed}
GET myapi.com/payments/123/items -- {payments/123/items/1, payments/123/items/2, ..., payments/123/items/n}
GET myapi.com/payments/123/items/3
where {...} denotes the possible transfer options returned by the server.
I could significantly lower the amount of requests by embedding data, but then I would be sending huge amounts of unrequested data.
Are there any best practices how to actually work with hypermedia APIs?