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

10-01.png

10.1 Overview of network communication concerns

10.1.1 Setting the scene

10.1.2 Analyzing the problems

10.2 Ensuring network communication efficiency at the protocol level

10.2.1 Activating compression and persistent connections

10.2.2 Enabling caching and conditional requests

10.2.3 Choosing cache policies

10.3 Ensuring network communication efficiency at the design level

10.3.1 Enabling filtering

10.3.2 Choosing relevant data for list representations

10.3.3 Aggregating data

10.3.4 Proposing different representations

10.3.5 Enabling expansion

10.3.6 Enabling querying

10.3.7 Providing more relevant data and goals

10.3.8 Creating different API layers

Summary

sitemap