mirror of
https://github.com/LukeHagar/plex-sdk-docs.git
synced 2025-12-07 12:37:44 +00:00
27 lines
951 B
Plaintext
27 lines
951 B
Plaintext
{/* Start Go Custom HTTP Client */}
|
|
The Go SDK makes API calls that wrap an internal HTTP client. The requirements for the HTTP client are very simple. It must match this interface:
|
|
|
|
```go
|
|
type HTTPClient interface {
|
|
Do(req *http.Request) (*http.Response, error)
|
|
}
|
|
```
|
|
|
|
The built-in `net/http` client satisfies this interface and a default client based on the built-in is provided by default. To replace this default with a client of your own, you can implement this interface yourself or provide your own client configured as desired. Here's a simple example, which adds a client with a 30 second timeout.
|
|
|
|
```go
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
"github.com/myorg/your-go-sdk"
|
|
)
|
|
|
|
var (
|
|
httpClient = &http.Client{Timeout: 30 * time.Second}
|
|
sdkClient = sdk.New(sdk.WithClient(httpClient))
|
|
)
|
|
```
|
|
|
|
This can be a convenient way to configure timeouts, cookies, proxies, custom headers, and other low-level configuration.
|
|
{/* End Go Custom HTTP Client */}
|