Skip to main content

APIClient

Protocol defining the interfaces and capabilities that API clients can conform to.

This provides a common pattern for network operations to be performed, and to centralize boilerplate handling of URL requests, provide customization extensions, and normalize response processing and argument handling.

The intent for this is to:

  • Abstract the patterns for how network operations are performed
  • Provide consistent capabilities for developers to extend and monitor network operations
  • Enable consistent testing and mocking support
  • Ensure consistency in lower-level network interactions across a variety of SDKs and library components which may be built by different teams.

While it would be ideal for implementors to follow the same naming and patterns for these interfaces, it's understood that different languages and environments tend to follow different patterns.

Depending on the language this SDK is being built for, these interfaces should provide inspiration about the sorts of capabilities the SDK should enable.

Index

Properties

optionalreadonlyadditionalHttpHeaders

additionalHttpHeaders?: {}

Any additional headers that should be added to all requests sent through this client.


Type declaration

  • [index string]: string

readonlybaseURL

baseURL: URL

The base URL requests are performed against.

This is used when request types may define their path as relative, and can inherit the URL they should be sent to through the client.

readonlynetwork

network: any

The network instance requests are sent through.

optionalreadonlyrequestIdHeader

requestIdHeader?: String

The name of the HTTP response header where unique request IDs can be found.

readonlyuserAgent

userAgent: String

The User-Agent string to be sent along with all outgoing requests.

Methods

didSend

  • Invoked when a request fails.


    Parameters

    Returns void

optionalerror

  • error(fromData: string): Error
  • Parses HTTP response body data when a request fails.

    • Returns: Error instance, if any, described within the data.

    Parameters

    • fromData: string

    Returns Error

send

shouldRetry

  • Provides the APIClient.Retry configurations from the delegate in response to a retry request.


    Parameters

    Returns APIRetry

willSend

  • Invoked immediately prior to a URLRequest being converted to a DataTask.


    Parameters

    Returns void