api concepts

How an API Works

Understanding the high-level overview of how APIs work and the components involved will help you effectively communicate with team members.

Introduction

As a reminder, an API enables communication between different software applications by defining rules for how they interact. Let’s explore the common steps and components involved when integrating with an API.

Common API Request Flow

How an API works
  1. Request Initiation: A client application, such as a browser or mobile app, sends a request to an API server indicating the type of operation requested and any important data required by the operation. This request specifies the desired operation (e.g., retrieving user data or submitting a form) and often includes relevant data or parameters.

  2. API Gateway Processing: The request first passes through an API gateway, a management layer that acts as a gatekeeper. The gateway validates the request by:
    • Authenticating credentials (e.g., API keys, tokens) to ensure the client is who they claim to be.
    • Authorizing the request by checking if the client has permission to perform the requested API operation.
  3. Forwarding or Rejecting the Request: If the request fails the authorization check, an error response is immediately returned to the client application. Otherwise, the API gateway forwards it to the appropriate API server for processing.

  4. Server-Side Operations: The API server processes the request. This often involves:
    • Connecting to a backend database to retrieve, store, or update data based on the request.
    • Performing any necessary business logic or transformations.
  5. Response Generation: Once the operation is complete, the API server generates a response. This response typically includes the requested data or a status message indicating success or failure.

  6. Response Delivery: The response is sent back through the API gateway, which ensures it is appropriately formatted and compliant with any policies before returning it to the client application.

This seamless interaction allows client applications to access and manipulate data or services without needing to know the underlying system’s complexities.

Terminology Used in This Example

For reference the following terminology is used in the example, above:

  • Client application: The application making the API call. This could be a web app, mobile app, or code running on a server that is performing work on behalf of someone.
  • API operation: An API has one or more operations that it offers. This might be “Get Current Weather Conditions” or “Get Upcoming Weather Forecast”. Each operation may require specific input data and will respond with a specific response containing the data requested.
  • API request: Contains the specific details from the client application about the API operation that is to be executed on the API server.
  • API gateway: An optional but common component that protects the API server from unauthorized access.
  • API server: Code running on a server that knows how to process a request, often by accessing one or more databases or other backend systems to fulfill the request.
  • API response: The data sent back to the client application as a result of a request. The response may contain the requested data or may contain an error message if the request could not be processed successfully.