Skip to content

Commit

Permalink
add examples for maps.Collect()
Browse files Browse the repository at this point in the history
  • Loading branch information
efectn committed Dec 9, 2024
1 parent cd9b6c9 commit 0b71163
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
23 changes: 23 additions & 0 deletions docs/client/request.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,29 @@ Header Key: Test, Header Value: [123456 654321]

</details>

```go title="Example with maps.Collect()"
req := client.AcquireRequest()

req.AddHeader("Golang", "Fiber")
req.AddHeader("Test", "123456")
req.AddHeader("Test", "654321")

headers := maps.Collect(req.Headers()) // Collect all headers into a map
for k, v := range headers {
fmt.Printf("Header Key: %s, Header Value: %v\n", k, v)
}
```

<details>
<summary>Click here to see the result</summary>

```sh
Header Key: Golang, Header Value: [Fiber]
Header Key: Test, Header Value: [123456 654321]
```

</details>

### AddHeader

AddHeader method adds a single header field and its value in the request instance.
Expand Down
25 changes: 25 additions & 0 deletions docs/client/response.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,31 @@ Access-Control-Allow-Credentials => true

</details>

```go title="Example with maps.Collect()"
resp, err := client.Get("https://httpbin.org/get")
if err != nil {
panic(err)
}

headers := maps.Collect(resp.Headers()) // Collect all headers into a map
for key, values := range headers {
fmt.Printf("%s => %s\n", key, strings.Join(values, ", "))
}
```

<details>

<summary>Click here to see the result</summary>

```text
Date => Wed, 04 Dec 2024 15:28:29 GMT
Connection => keep-alive
Access-Control-Allow-Origin => *
Access-Control-Allow-Credentials => true
```

</details>

## Cookies

Cookies method to access all the response cookies.
Expand Down

0 comments on commit 0b71163

Please sign in to comment.