Knowledgebase

Calling Web Services and APIs Print

  • python, guide, howto, solution, zillionkinghost, hosting, support
  • 0

Talking to other systems.

WHAT AN API CALL INVOLVES

Sending a request to a URL, and receiving a response.

WHAT TO USE

An established HTTP library rather than low-level facilities.

WHAT TO ALWAYS DO

Check the response status before using the content Set a timeout Handle failure

THE TIMEOUT POINT

Without one, a request can hang indefinitely and stop your program.

Always set it.

WHAT TO HANDLE

Network failures Unexpected status codes Responses that are not the format you expected Rate limits

RATE LIMITS

Most services limit how often you may call them.

Respect them, and handle the response when you exceed one.

WHAT TO DO ON FAILURE

Retry, with an increasing delay, for temporary failures.

Not for failures that will not resolve.

WHAT TO KEEP OUT OF CODE

API keys and credentials.

Read them from the environment.

WHAT TO LOG

Enough to diagnose a failure, without logging credentials.

WHAT TO VALIDATE

The response structure, before relying on it.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot