Skip to main content
Beginnerconceptual

What is an API, and how would you integrate a third-party API into your project?

ReportedSource: GeeksforGeeks interview experience: Deloitte Product Engineering Analyst 2024

Quick answer

An API is a contract for using another system's functions/data (REST/GraphQL endpoints, auth, errors). Integrate by reading docs, keeping keys server-side in secrets, calling with timeouts, retries/backoff, caching, wrapping it in an adapter class, testing with mocks and monitoring.

API (Application Programming Interface). A defined contract that lets one piece of software use another's functionality or data without knowing its internals: endpoints, request/response formats, authentication and error codes. Web APIs are usually REST (HTTP + JSON) or GraphQL; libraries and operating systems also expose APIs.

Integrating a third-party API, step by step.

  1. Read the docs: endpoints, rate limits, pricing, sandbox environment.
  2. Get credentials (API key or OAuth); store them in environment variables or a secrets manager, never in code.
  3. Call it from the backend, not the browser, when the key is secret.
main.py
import os, requests
resp = requests.get('https://api.example.com/v1/weather',
                    params={'city': 'Pune'},
                    headers={'Authorization': f"Bearer {os.environ['WEATHER_KEY']}"},
                    timeout=5)
resp.raise_for_status()
data = resp.json()
  1. Handle failures: timeouts, retries with backoff for 5xx/429, fallbacks, and clear error messages.
  2. Cache responses that don't change often to save cost and stay within rate limits.
  3. Wrap it in your own service class so the rest of the code doesn't depend on the vendor's format; write tests with mocked responses.
  4. Monitor usage, latency and errors.

Discussion