Client-Adapting APIs

Learn how to identify the client type and make the API response flexible.

Introduction

In the real world, an API endpoint gets called by numerous types of end devices (such as mobile phones, laptops, tablets, and so on). Depending on the type of end device or situation, API responses can be flexible. For example:

  • A YouTube video's resolution provided by the server is different for a mobile device compared to a desktop browser. This can be due to the width of the screen, transfer protocol, and so on.

  • Instagram stories don’t have music for some regions. After identifying the region, the system may decide to add or remove music for users.

Therefore, an API generating the same response for every client request may not be suitable for all end devices. In essence, a flexible API response refers to the flexibility in terms of the response generated and resources provided by servers to clients—mainly depending on the user and client (such as its type, version, and so on).

To generate a flexible response, we need to provide flexibility on the client- or server-side. We’ll discuss different ways to make the response flexible using various examples in this lesson.

Approaches

Adaptive responses can be achieved in the following ways:

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.