The Design of Web APIs, Second Edition cover
welcome to this free extract from
an online version of the Manning book.
to read more
or

13 Designing an efficient API

 

This chapter covers

  • Optimizing design when necessary
  • Enabling caching and conditional readings
  • Optimizing data volume
  • Processing multiple elements with bulk operations
  • Considering an optimization-specific API layer

Since the Shopping company implemented its newly redesigned API with additional features, the number of product purchases has dropped. Website and mobile analytics indicate that users are experiencing wait times of over 500 ms when searching for products. This problem is due not to a missing index in the database or inadequate infrastructure but rather to the inefficient design of the API. Searching for products necessitates firing multiple API requests for each product found to gather all the necessary data and display it to users.

Concern about efficiency is not limited to the implementation level. An efficient API design can lead to benefits including optimized smartphone battery usage, reduced wait times for end users, and minimal effects on 5G data plans. Furthermore, it can enhance provider infrastructure efficiency, reducing cloud infrastructure costs through reduced CPU usage and data downloads.

13.1 An overview of API efficiency

13.1.1 How an API can be inefficient

13.1.2 When to be concerned about efficiency

13.1.3 How design contributes to API efficiency

13.2 Optimizing the design only when necessary

13.2.1 Ensuring HTTP configuration efficiency

13.2.2 Limiting API usage with rate-limiting

13.2.3 Enhancing response with rate-limiting headers

13.2.4 Finding the true root cause

13.3 Focusing on user needs and user-friendliness to be efficient

13.3.1 What we’ve learned so far

13.3.2 Analyzing an inefficient flow

13.3.3 Optimizing each operation

13.3.4 Rethinking the flow

13.4 Enabling caching and conditional readings

13.4.1 An overview of caching and conditional readings

13.4.2 Not letting consumers decide how to cache

13.4.3 Defining caching policies based on data and context

13.4.4 Returning cache directives

13.4.5 Retrieving data only when modified

Summary