Skip to content

Commit 17be9e9

Browse files
Add docs from gofiber/fiber@a167c6f
1 parent 2582a2e commit 17be9e9

File tree

3 files changed

+83
-2
lines changed

3 files changed

+83
-2
lines changed

docs/core/client/examples.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,79 @@ func main() {
151151
</TabItem>
152152
</Tabs>
153153

154+
## Reusing fasthttp transports
155+
156+
The Fiber client can wrap existing `fasthttp` clients so that you can reuse
157+
connection pools, custom dialers, or load-balancing logic that is already tuned
158+
for your infrastructure.
159+
160+
### HostClient
161+
162+
```go
163+
package main
164+
165+
import (
166+
"log"
167+
"time"
168+
169+
"github.com/gofiber/fiber/v3/client"
170+
"github.com/valyala/fasthttp"
171+
)
172+
173+
func main() {
174+
hc := &fasthttp.HostClient{
175+
Addr: "api.internal:443",
176+
IsTLS: true,
177+
MaxConnDuration: 30 * time.Second,
178+
MaxIdleConnDuration: 10 * time.Second,
179+
}
180+
181+
cc := client.NewWithHostClient(hc)
182+
183+
resp, err := cc.Get("https://api.internal:443/status")
184+
if err != nil {
185+
log.Fatal(err)
186+
}
187+
188+
log.Printf("status=%d body=%s", resp.StatusCode(), resp.Body())
189+
}
190+
```
191+
192+
### LBClient
193+
194+
```go
195+
package main
196+
197+
import (
198+
"log"
199+
"time"
200+
201+
"github.com/gofiber/fiber/v3/client"
202+
"github.com/valyala/fasthttp"
203+
)
204+
205+
func main() {
206+
lb := &fasthttp.LBClient{
207+
Timeout: 2 * time.Second,
208+
Clients: []fasthttp.BalancingClient{
209+
&fasthttp.HostClient{Addr: "edge-1.internal:8080"},
210+
&fasthttp.HostClient{Addr: "edge-2.internal:8080"},
211+
},
212+
}
213+
214+
cc := client.NewWithLBClient(lb)
215+
216+
// Per-request overrides such as redirects, retries, TLS, and proxy dialers
217+
// are shared across every host client managed by the load balancer.
218+
resp, err := cc.Get("http://service.internal/api")
219+
if err != nil {
220+
log.Fatal(err)
221+
}
222+
223+
log.Printf("status=%d body=%s", resp.StatusCode(), resp.Body())
224+
}
225+
```
226+
154227
## Cookie jar
155228

156229
The client can store and reuse cookies between requests by attaching a cookie jar.

docs/core/client/rest.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,8 @@ func (c *Client) SetCBORUnmarshal(f utils.CBORUnmarshal) *Client
359359

360360
### TLSConfig
361361

362-
Returns the client's TLS configuration. If none is set, it initializes a new one.
362+
Returns the client's TLS configuration. If none is set, it initializes a new
363+
configuration with `MinVersion` defaulting to TLS 1.2.
363364

364365
```go title="Signature"
365366
func (c *Client) TLSConfig() *tls.Config
@@ -762,7 +763,8 @@ func (c *Client) Logger() log.CommonLogger
762763

763764
### Reset
764765

765-
Clears and resets the client to its default state.
766+
Clears and resets the client to its default state and reinstates the default
767+
`fasthttp.Client` transport.
766768

767769
```go title="Signature"
768770
func (c *Client) Reset()

docs/core/whats_new.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,12 @@ The default redirect status code has been updated from `302 Found` to `303 See O
774774
The Gofiber client has been completely rebuilt. It includes numerous new features such as Cookiejar, request/response hooks, and more.
775775
You can take a look to [client docs](./client/rest.md) to see what's new with the client.
776776

777+
### Fasthttp transport integration
778+
779+
- `client.NewWithHostClient` and `client.NewWithLBClient` allow you to plug existing `fasthttp` clients directly into Fiber while keeping retries, redirects, and hook logic consistent.
780+
- Dialer, TLS, and proxy helpers now update every host client inside a load balancer, so complex pools inherit the same configuration.
781+
- The Fiber client exposes `Do`, `DoTimeout`, `DoDeadline`, and `CloseIdleConnections`, matching the surface area of the wrapped fasthttp transports.
782+
777783
## 🧰 Generic functions
778784

779785
Fiber v3 introduces new generic functions that provide additional utility and flexibility for developers. These functions are designed to simplify common tasks and improve code readability.

0 commit comments

Comments
 (0)