Knowledgebase

Consuming External APIs Print

  • phplaravel, caching, guide, howto, solution, zillionkinghost, hosting, support
  • 0

Calling other services.

WHAT THE FRAMEWORK PROVIDES

An HTTP client with a clear interface.

WHAT TO ALWAYS SET

A timeout.

Without one, a hanging request holds your process.

WHAT TO HANDLE

Network failure Unexpected status codes Responses not in the expected format Rate limits

WHAT TO IMPLEMENT

Retries with increasing delay, for temporary failures only.

WHAT NOT TO RETRY

Failures that will not resolve, such as invalid credentials.

WHERE TO PUT THE CODE

A dedicated class per service, not scattered through controllers.

WHY

So it can be substituted in tests and changed in one place.

WHAT TO KEEP IN CONFIGURATION

Endpoints and credentials.

WHAT TO QUEUE

Calls made during a request, where the result is not needed immediately.

WHAT TO CACHE

Responses that change rarely.

WHAT TO VALIDATE

The response structure, before relying on it.

WHAT TO LOG

Failures, with enough context to diagnose, and never the credentials.


Was this answer helpful?
Back

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


Trustpilot