A recent post on the Instavest Blog covered the topic of dealing with unreliable web APIs, such as ones that provide inconsistent error responses or suffer from reliability issues. The author offered these 5 tips to ease the pain for developers dealing with these kinds of APIs.
- Retry Loops – Since undocumented error responses should make up only a small percentage of requests, retrying the request twice could take success rate of requests from, for example, 90% up to 99.9%
- Thorough Logging – Keeping accurate and detailed records of the success or failure of every API request can speed up debugging and act as a trustworthy audit trail
- Set up Automatic Emails – An extension of the logging process, sending error reporting emails with diagnostics reports to tech support teams can help maintain third-party APIs that are non-critical, but may still be important from a UX perspective
- Use Error-Reporting Tools – Whether you are using third-party APIs or not, you should integrate some form of middleware that reports on unhandled exceptions, including frequency of instances and the users affected
- Track Response Latency and Warn Yourself Internally – Keeping a record of response latency can help you understand the reasons it might be happening. This data can be used to improve your processes, such as timing heavy data pulls to times where third-party APIs are more available.