DEV Community

Matt Hawkins for Hoss

Posted on • Originally published at hoss.com

3 Common API Integration Mistakes and How to Avoid Them

Alt Text

If you’re building an app or have already deployed one, you probably used a good number of third-party APIs. After all, why build it yourself when you can plug in an API with the functionality you need? However, it’s natural to make certain mistakes when integrating APIs, and these mistakes can negatively impact app performance and user experience. This post highlights some common mistakes developers make when integrating APIs with apps and how to avoid them.

1. Don't Overlook Legalities Concerning API Use and User Data

When it comes to the terms of use, many developers make the mistake of only reviewing the policy at the time of integration. API providers sometimes change the terms of use for their APIs, and they don’t always notify users. If you’re using an API and are not following its current terms of use, the provider could ban you from using the API or you could face legal consequences.

It’s also important to consider the legalities of the data your app will store. Quite a few countries have regulations regarding user data, and your app must follow all applicable data privacy laws. Otherwise, you could face expensive fines and stiff penalties.

2. Don't Assume Third-Party APIs Will Always Respond as Expected

Some developers may not take the time to test and monitor third-party APIs for errors. Developers may also fail to add code that enables an app to work properly, even when an API doesn’t respond or returns an error. APIs become non-responsive or return errors for many reasons, including:

  • Downtime – Many API providers commit to an API uptime of 99-99.99%. But the reality is that every API will eventually experience a shutdown, whether it’s planned or unplanned.
  • Connection Timeout – Many providers program their APIs with default timeout values that are too short.
  • Rate Limits – API call volumes tend to be low during app development, but once the app is deployed, the call volume may hit the rate limit.
  • Bad Request – There are many reasons an API might return a “400 Bad Request Error.” It usually takes a lot of digging to figure out the root cause.

Don't make the mistake of assuming the APIs you’re using work perfectly. They might have hidden issues and you want to find errors before your customers do.

3. Keep an Eye Out for API Changes

It is a mistake to assume the providers of the APIs you’re using will always alert you of changes. While most providers alert users to changes with their APIs, some don’t. And the only indication an API change may be buried deep within the documentation.

Sometimes providers will change the design of an API or deprecate an API. They might change how methods are called or remove API functionality. They might release a new version of an API, which usually means new endpoint URLs. These API changes can break integrations and even bring down your app.

How Can You Avoid These API Integration Mistakes?

With the right tools and coding techniques, you can avoid the above API integration mistakes. Here are a few examples:

Review the Terms of Use and Research Data Privacy Laws

If you’re developing an app, you need to pay close attention to the terms of service for each third-party API you use. You must also make sure your app and any APIs you use comply with applicable data privacy laws. For example, if any users live in Europe, then your app must comply with GDPR. Do you have any users residing in California? Then you need to comply with CCPA. You need to do your research and code your app to comply with every applicable data privacy law. You should also use tools that enable you to track and control personal user data.

Code Your App to Handle Non-Responsive APIs and Errors

You can program your app to handle non-responsive APIs in any number of ways. For example, you could add code for asynchronous scripting, caching and automatic retries.

  • Asynchronous Scripting - App users shouldn’t have to wait for all the external scripts and APIs to load before they can view the main content. Asynchronous scripting allows the content of an app or a web page to load without having to wait for external resources. So, if an API is non-responsive, the content will load regardless. Many scripting languages feature asynchronous functionality, including JavaScript.
  • Cache API Responses - Caching API responses allows third-party API data to be stored on your server or in the client itself. The client retrieves data from a cache file instead of from the API server directly. Caching works best for API data that doesn’t change frequently. You can use caching to improve performance and potentially avoid outages or rate limits.
  • Automatic Retries - You should add code to your app that enables automatic retries. If an API is non-responsive or comes back with an error, the code automatically sends another API request. Most failed API calls can be retried immediately with successful results.

You should also code your app to handle the HTTP status codes for each API you use. Some providers publish detailed tutorials about how to do this.

Monitor Third-Party APIs for Changes

It’s crucial that you monitor every API for changes in availability, performance, speed and data format. Since most providers update the API documentation and changelog before sending out an update to users, you could periodically check these items for every API you use. A better option is to use API management software, as it monitors third-party APIs and alerts you to changes automatically.

Choose the Right Tools and Techniques

Choose your development tools and coding techniques wisely and you can avoid making these common API integration mistakes.

Hoss provides free visibility into the APIs you consume. Keep track of performance, get error alerts and reduce the amount of time spent debugging integrations.

Top comments (0)