Recently, I have been studying Teacher Xu Hao’s “How to Implement Business Modeling”. The 11th lecture “Realizing Model as RESTful API (Part 2)” mentioned a very interesting concept of progressive consumption.

I was very impressed with this chapter. Because our business often has multiple pages with similar but not identical content. At this point, I saw that the project was riddled with a lot of duplicate code, with almost every page rewritten as a Controller-service-Mapper. Over time, such code becomes a very cumbersome historical baggage that is very difficult to maintain.

Teacher Xu Hao’s article tells us that we can solve this problem through gradual consumption. Incremental spending is actually quite common. There should be code all over the place up front. A page requires a lot of data, and rather than being tiled and fetched directly from the back end, it can be fetched increments through “service enhancement”. Similar to the teacher Xu Hao cited an example in the article

Content-Type: application/hal+xml
<resource rel="self" href="/orders/523">
    <link rel="warehouse" href="/warehouse/56"/>
    <link rel="invoice" href="/invoices/873"/>
    <currency>USD</currency>
    <status>shipped</status>
    <total>10.20</total>
</resource>Content-Type: application/hal+json { "_links": { "self": { "href": "/orders/523" }, "warehouse": { "href": "/ warehouse / 56"}, "invoice" : {" href ":"/invoices / 873 "}}, "currency" : "$"," status ":" shipped ", "total" : 10.20}Copy the code

In fact, we can also use this approach for the entire service. Provide a generic interface and then “enhance” it to meet different functional requirements. This can maintain a stable state on the server. Of course, there will be performance problems in doing so, but Xu hao’s idea is to solve them by caching.

In practical application, we do not necessarily follow the practice provided by the teacher, but more important is to understand the idea. For example, in our project, there may be some obstacles and costs to implement the teacher’s approach. Because this needs the cooperation of the whole project team. But this idea can guide us to write services in a hierarchical structure, with a stable bottom layer and a top layer combining the bottom interfaces to meet different needs.