Skip to content

Commit

Permalink
create docs
Browse files Browse the repository at this point in the history
  • Loading branch information
efectn committed Dec 4, 2024
1 parent 7488d53 commit 0343f06
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ coverage:
format:
go run mvdan.cc/gofumpt@latest -w -l .

## markdown: 🎨 Find markdown format issues (Requires markdownlint-cli)
## markdown: 🎨 Find markdown format issues (Requires markdownlint-cli2)
.PHONY: markdown
markdown:
markdownlint-cli2 "**/*.md" "#vendor"
Expand Down
6 changes: 5 additions & 1 deletion client/response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func Test_Response_Headers(t *testing.T) {
c.Response().Header.Add("foo", "bar2")
c.Response().Header.Add("foo2", "bar")

return c.SendString("helo world")
return c.SendString("hello world")
})
})
defer server.stop()
Expand All @@ -226,10 +226,14 @@ func Test_Response_Headers(t *testing.T) {
headers[k] = append(headers[k], v...)
}

require.Equal(t, "hello world", resp.String())

require.Contains(t, headers["Foo"], "bar")
require.Contains(t, headers["Foo"], "bar2")
require.Contains(t, headers["Foo2"], "bar")

require.Len(t, headers, 3) // Foo + Foo2 + Date

resp.Close()
}

Expand Down
90 changes: 90 additions & 0 deletions docs/client/request.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,38 @@ Header method returns header value via key, this method will visit all field in
func (r *Request) Header(key string) []string
```

### Headers

Headers returns all headers in the request using an iterator. You can use `maps.Collect()` to collect all headers into a map.

The returned value is valid until the request object is released. Any future calls to Headers method will return the modified value. Do not store references to returned value. Make copies instead.

```go title="Signature"
func (r *Request) Headers() iter.Seq2[string, []string]
```

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

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

for k, v := range req.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 Expand Up @@ -320,6 +352,15 @@ Param method returns params value via key, this method will visit all field in t
func (r *Request) Param(key string) []string
```

### Params

Params returns all params in the request using an iterator. You can use `maps.Collect()` to collect all params into a map.
The returned value is valid until the request object is released. Any future calls to Params method will return the modified value. Do not store references to returned value. Make copies instead.

```go title="Signature"
func (r *Request) Params() iter.Seq2[string, []string]
```

### AddParam

AddParam method adds a single param field and its value in the request instance.
Expand Down Expand Up @@ -502,6 +543,14 @@ Cookie returns the cookie set in the request instance. If the cookie doesn't exi
func (r *Request) Cookie(key string) string
```

### Cookies

Cookies returns all cookies in the request using an iterator. You can use `maps.Collect()` to collect all cookies into a map.

```go title="Signature"
func (r *Request) Cookies() iter.Seq2[string, string]
```

### SetCookie

SetCookie method sets a single cookie field and its value in the request instance.
Expand Down Expand Up @@ -575,6 +624,14 @@ PathParam returns the path param set in the request instance. If the path param
func (r *Request) PathParam(key string) string
```

### PathParams

PathParams returns all path params in the request using an iterator. You can use `maps.Collect()` to collect all path params into a map.

```go title="Signature"
func (r *Request) PathParams() iter.Seq2[string, string]
```

### SetPathParam

SetPathParam method sets a single path param field and its value in the request instance.
Expand Down Expand Up @@ -682,6 +739,14 @@ FormData method returns form data value via key, this method will visit all fiel
func (r *Request) FormData(key string) []string
```

### FormDatas

FormDatas returns all form data in the request using an iterator. You can use `maps.Collect()` to collect all form data into a map.

```go title="Signature"
func (r *Request) FormDatas() iter.Seq2[string, []string]
```

### AddFormData

AddFormData method adds a single form data field and its value in the request instance.
Expand Down Expand Up @@ -817,6 +882,15 @@ If the name field is empty, it will try to match path.
func (r *Request) File(name string) *File
```

### Files

Files method returns all files in request instance.
The returned value is valid until the request object is released. Any future calls to Files method will return the modified value. Do not store references to returned value. Make copies instead.

```go title="Signature"
func (r *Request) Files() []*File
```

### FileByPath

FileByPath returns file ptr store in request obj by path.
Expand Down Expand Up @@ -1063,6 +1137,14 @@ type QueryParam struct {
}
```

### Keys

Keys method returns all keys in the query params.

```go title="Signature"
func (p *QueryParam) Keys() []string
```

### AddParams

AddParams receive a map and add each value to param.
Expand Down Expand Up @@ -1242,6 +1324,14 @@ type FormData struct {
}
```

### Keys

Keys method returns all keys in the form data.

```go title="Signature"
func (f *FormData) Keys() []string
```

### AddData

AddData method is a wrapper of Args's Add method.
Expand Down
34 changes: 34 additions & 0 deletions docs/client/response.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,43 @@ Header method returns the response headers.
func (r *Response) Header(key string) string
```

## Headers

Headers returns all headers in the response using an iterator. You can use `maps.Collect()` to collect all headers into a map.
The returned value is valid until the response object is released. Any future calls to Headers method will return the modified value. Do not store references to returned value. Make copies instead.

```go title="Signature"
func (r *Response) Headers() iter.Seq2[string, []string]
```

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

for key, values := range resp.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.
The returned value is valid until the response object is released. Any future calls to Cookies method will return the modified value. Do not store references to returned value. Make copies instead.

```go title="Signature"
func (r *Response) Cookies() []*fasthttp.Cookie
Expand Down

0 comments on commit 0343f06

Please sign in to comment.