10 Designing a network-efficient API
This chapter covers
- Web API network communication concerns
- Using compression, caching, and conditional requests
- Optimizing API design to make fewer calls and exchange less data
So far, we’ve focused on designing APIs that provide usable, secure, and evolvable representations of goals that make sense for consumers and hide internal concerns. But in reality, we’ve learned to design ideal laboratory APIs, ignoring most of the context in which they are used—especially the network context.
Network communication efficiency is an important topic that any API designer must be aware of. Indeed, communication efficiency is important in our day-to-day lives. When you have a conversation with someone, either by speaking or by instant message or email, sometimes you want the full story to get all the possible background information, and sometimes you want the person you communicate with to get straight to the point and tell you only the bit you need to know. If you get the full story, but you wanted just a specific bit of it, you will have to waste time listening to or reading all of it to get what you want. This can be frustrating, and it can even have serious consequences, like missing out on an opportunity.
Choosing the wrong way of communicating information can have negative impacts in our daily lives. The same is true for APIs that provide inefficient network communications, as shown in figure 10.1.
Figure 10.1 Network concerns influence API design