@@ -26,6 +26,8 @@ type EndpointType string
2626const (
2727 // EndpointTypeREST represents a REST API endpoint
2828 EndpointTypeREST EndpointType = "rest"
29+ // EndpointTypeFormURLEncoded represents a REST API endpoint using application/x-www-form-urlencoded
30+ EndpointTypeFormURLEncoded EndpointType = "form-urlencoded"
2931 // EndpointTypeGRPC represents a gRPC API endpoint
3032 EndpointTypeGRPC EndpointType = "grpc"
3133 // EndpointTypeSOAP represents a SOAP API endpoint
@@ -38,7 +40,7 @@ type Endpoint struct {
3840 FriendlyName string
3941 // URL is the endpoint URL/address
4042 URL string
41- // Type is the type of endpoint (REST, gRPC, SOAP)
43+ // Type is the type of endpoint (REST, form-urlencoded REST, gRPC, SOAP)
4244 Type EndpointType
4345 // Timeout is the timeout duration for API calls
4446 // If set to 0 or unset, defaults to 30 seconds
@@ -54,6 +56,11 @@ type Endpoint struct {
5456 // If set to 0 or unset, no retries are attempted
5557 // Retries use exponential backoff: 1s, 2s, 4s, 8s, etc.
5658 MaxRetries int
59+ // RetryErrorRange is the hundredths place of the error code range for which retries should be attempted
60+ // If set to 0 or unset, retries are attempted for all error codes based on MaxRetries
61+ // For example, if set to 5, retries will only be attempted for 5xx error codes (e.g., 500-599)
62+ // This allows for more granular control over which errors should trigger retries
63+ RetryErrorRange int
5764 // Config is the optional API caller configuration (TLS, certificates, etc.)
5865 // If set on the Endpoint, it will be used as the default for all calls
5966 // Can be overridden by passing a non-nil config to Call()
@@ -68,6 +75,8 @@ type Endpoint struct {
6875// - "body" (any): Request body
6976// REST-specific parameters:
7077// - "headers" (map[string]string): HTTP headers
78+ // Form-urlencoded REST parameters:
79+ // - "body" should be url.Values, map[string]string, map[string][]string, or map[string]any
7180// SOAP-specific parameters:
7281// - "soapAction" (string): SOAP action header
7382// - "headers" (map[string]string): Additional HTTP headers
@@ -154,6 +163,10 @@ func (e *Endpoint) Call(params map[string]any) (map[string]any, error) {
154163 if maxRetries < 0 {
155164 maxRetries = 0
156165 }
166+ retryErrRange := e .RetryErrorRange
167+ if retryErrRange < 0 {
168+ retryErrRange = 0
169+ }
157170
158171 for attempt := 0 ; attempt <= maxRetries ; attempt ++ {
159172 // Recreate context for each retry attempt
@@ -185,6 +198,13 @@ func (e *Endpoint) Call(params map[string]any) (map[string]any, error) {
185198 // Timeout occurred, will retry
186199 continue
187200 }
201+ // Check for HTTP error codes if response is available and RetryErrorRange is set
202+ if retryErrRange > 0 && response != nil {
203+ if response .StatusCode >= retryErrRange * 100 && response .StatusCode < (retryErrRange + 1 )* 100 {
204+ // Error code is within the specified retry range, will retry
205+ continue
206+ }
207+ }
188208 }
189209
190210 // Success or non-timeout error, break out of retry loop
@@ -387,6 +407,8 @@ func newAPICallerInternal(endpoint Endpoint, config *APICallerConfig, cacheKey s
387407 switch endpoint .Type {
388408 case EndpointTypeREST :
389409 caller .client , err = NewRESTClient (endpoint , config )
410+ case EndpointTypeFormURLEncoded :
411+ caller .client , err = NewRESTClient (endpoint , config )
390412 case EndpointTypeGRPC :
391413 caller .client , err = NewGRPCClient (endpoint , config )
392414 case EndpointTypeSOAP :
0 commit comments