The SyncariRestClient is a sophisticated component of the Custom Synapse SDK, built on top of the widely used Requests library in Python (Requests Documentation). This client facilitates streamlined HTTP requests, incorporating robust error handling and automatic retry mechanisms, making it a crucial tool for reliable API interactions.
Features
- Error Handling: Automatically manages HTTP errors, wrapping them in a SyncariException that encapsulates an ErrorResponse detailing the issue.
- Automatic Retries: Implements a retry strategy for transient errors (HTTP status codes 429, 500, 502, 503, and 504) with customizable retry counts and backoff strategies.
Initialization
To ensure the SyncariRestClient is readily available across your Synapse's methods, initialize it within the constructor method (__init__). This client supports both dynamic and static endpoint configurations:
Dynamic Endpoint Example:
self.client = SyncariRestClient(self.connection.authConfig.endpoint, self.connection.authConfig)
Static Endpoint Example:
self.client = SyncariRestClient('https://www.yourendpoint.com/api', self.connection.authConfig)
Success and Retry Handling
Success Responses: The client recognizes HTTP status codes 200, 201, 202, and 204 as successful outcomes. All other codes trigger a SyncariException that includes an ErrorResponse detailing the failure.
Retry Strategy: By default, the client retries requests on receiving HTTP status codes 429, 500, 502, 503, and 504. The default configuration attempts up to 5 retries with a backoff factor of 2. These parameters can be adjusted during client initialization to suit specific requirements.