I'm designing an API using Hypermedia concepts. I saw that is a good practice have a root route that returns the others API links to navigate.
Ex.: I made a request to http://myapi.com and it returns
{
links: [
{ 'rel': 'profile', href: '/profile' },
{ 'rel': 'orders', href: '/orders' },
{ 'rel': 'order_types', href: '/order_types' },
...
]
}
But, in this way, if the root had 20 resources it will be very large.
So, made a direct request to order_types instead request root and then request the order_types is a anti pattern?
It's a bit of a hard question to answer, because the first thing that comes to mind to me is: is it actually that large?
Right now for example each of your links takes around 40 bytes. For 20 resources that's 800 bytes. gzip the response (or brotli if you can support it) and you can make this much smaller. If your total file has some overhead (say another 200 bytes) and we assume 1KB, with something like gzip you can probably drop this back to 400 bytes or smaller.
You can set cache headers on this file so it only gets requested once in a blue moon.
So now your main question? Is it an anti-pattern. I would say yes, you should only have one bookmarked url.