REST resource: embedding VS related data related to it?

I have a REST system with article and author resources. As a rule, when accessing an article, I also want to find out the name of the author. I can create articles in several ways to accomplish this: A) embed a copy of the author’s name directly in the article; or B) include a URI in an article that points to the corresponding resource of the author.

Obviously, the disadvantage is that the author’s name is copied directly to the article’s resource. By duplicating information into multiple resources, I open myself up to conflicts between resources. After the author updates his name, the article resource may have its old name, and the author's resource a new one.

Perhaps if I do not cache articles, this will not be a problem? But in practical terms, speeding up and reducing the number of trips to the server is very desirable, so caching in the browser is what I shoot.

In scenario B, a reference to using a URI seems to be correct and more convenient for caching. But this doubles the number of calls to the server: each article requires a second (sequential) sampling of the Author. So, darling in a different way, especially if we are talking about multiple URIs for several other resources. When you display 50 articles at a time, this can go crazy.

I would like to hear how this problem is addressed by others. Are there any “best practices” essays worth reading?

+4
source share
1 answer

linking ... doubles the number of calls to the server: each article requires a second (sequential) sampling of the author.

REST includes cache restrictions for precisely this reason that a “second fetch” is not required at all if the data is already in your local cache (or may be a request that uses only partial network resources if the cache is intermediate or server). If your data can be designed to take advantage of this, you can reduce overall network traffic by orders of magnitude. If this is not possible, then it makes no sense to apply the REST architectural style, which depends on caching network efficiency - choose a different style, for example RPC.

+1
source

Source: https://habr.com/ru/post/1340397/


All Articles