Skip to content

Commit

Permalink
doc: Improve *fiber.Client section
Browse files Browse the repository at this point in the history
Enhanced the documentation for the *fiber.Client section, providing
a clear and concise example to help users better understand its usage.
  • Loading branch information
renanbastos93 committed Jul 24, 2023
1 parent b6a42cf commit 2390e6c
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion docs/api/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,48 @@ func (c *Client) Patch(url string) *Agent
func (c *Client) Delete(url string) *Agent
```

Here we can see a little example to simulate a proxy using our methods `*fiber.Agent`
```go
// Get something
func getSomething(c *fiber.Ctx) (err error) {
agent := fiber.Get("<URL>")
statusCode, body, errs := agent.Bytes()
if len(errs) > 0 {
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
"errs": errs,
})
}

var something fiber.Map
err = json.Unmarshal(body, &something)
if err != nil {
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
"err": err,
})
}

return c.Status(statusCode).JSON(something)
}

// Post something
func createSomething(c *fiber.Ctx) (err error) {
agent := fiber.Post("<URL>")
agent.Body(c.Body()) // set body received by request
statusCode, body, errs := agent.Bytes()
if len(errs) > 0 {
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
"errs": errs,
})
}

// pass status code and body received by the proxy
return c.Status(statusCode).Send(body)
}
```
Based on this short example, we can perceive that using the `*fiber.Client` is very straightforward and intuitive.

## ✨ Agent

## ✨ Agent
`Agent` is built on top of FastHTTP's [`HostClient`](https://github.com/valyala/fasthttp/blob/master/client.go#L603) which has lots of convenient helper methods such as dedicated methods for request methods.

### Parse
Expand Down

0 comments on commit 2390e6c

Please sign in to comment.