← Back to context

Comment by systemicdanna

3 years ago

API can be a very thin layer that a well constructed client can utilize right from the "view" (a React component). A template file in a backend framework is a one-way feature in the majority of cases. You have to construct and pass _all_ its context (or create helpers, global context, etc) every time. So the controller needs to request data, prepare it (template data manipulation is mostly minimal), pass it. Basically a controller starts doing too many things over time, too much business logic is added to accommodate pretty low featured templates.

> Don't you pass already massive JSON payloads from your API endpoints down to your client to update the views?

Not really. You send many parallel API requests from the client, each response is a smaller JSON. And when you navigate to the next page, most of its data is already in your state, so you have to request just the missing part (e.g. a different post). When you are constructing context for a page on the backend you have to provide all its context every time. The template doesn't make requests based on some logic.