Skip to content

Commit fa4c54a

Browse files
committed
change request/response markdown examples
1 parent 65c0448 commit fa4c54a

File tree

2 files changed

+57
-59
lines changed

2 files changed

+57
-59
lines changed

docs/client/request.md

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ The returned value is valid until the request object is released. Any future cal
220220
func (r *Request) Headers() iter.Seq2[string, []string]
221221
```
222222

223+
<details>
224+
<summary>Example</summary>
225+
223226
```go title="Example"
224227
req := client.AcquireRequest()
225228

@@ -232,16 +235,16 @@ for k, v := range req.Headers() {
232235
}
233236
```
234237

235-
<details>
236-
<summary>Click here to see the result</summary>
237-
238238
```sh
239239
Header Key: Golang, Header Value: [Fiber]
240240
Header Key: Test, Header Value: [123456 654321]
241241
```
242242

243243
</details>
244244

245+
<details>
246+
<summary>Example with maps.Collect()</summary>
247+
245248
```go title="Example with maps.Collect()"
246249
req := client.AcquireRequest()
247250

@@ -255,9 +258,6 @@ for k, v := range headers {
255258
}
256259
```
257260

258-
<details>
259-
<summary>Click here to see the result</summary>
260-
261261
```sh
262262
Header Key: Golang, Header Value: [Fiber]
263263
Header Key: Test, Header Value: [123456 654321]
@@ -273,6 +273,9 @@ AddHeader method adds a single header field and its value in the request instanc
273273
func (r *Request) AddHeader(key, val string) *Request
274274
```
275275

276+
<details>
277+
<summary>Example</summary>
278+
276279
```go title="Example"
277280
req := client.AcquireRequest()
278281
defer client.ReleaseRequest(req)
@@ -289,9 +292,6 @@ if err != nil {
289292
fmt.Println(resp.String())
290293
```
291294

292-
<details>
293-
<summary>Click here to see the result</summary>
294-
295295
```json
296296
{
297297
"headers": {
@@ -316,6 +316,9 @@ It will override the header which has been set in the client instance.
316316
func (r *Request) SetHeader(key, val string) *Request
317317
```
318318

319+
<details>
320+
<summary>Example</summary>
321+
319322
```go title="Example"
320323
req := client.AcquireRequest()
321324
defer client.ReleaseRequest(req)
@@ -331,9 +334,6 @@ if err != nil {
331334
fmt.Println(resp.String())
332335
```
333336

334-
<details>
335-
<summary>Click here to see the result</summary>
336-
337337
```json
338338
{
339339
"headers": {
@@ -391,6 +391,9 @@ AddParam method adds a single param field and its value in the request instance.
391391
func (r *Request) AddParam(key, val string) *Request
392392
```
393393

394+
<details>
395+
<summary>Example</summary>
396+
394397
```go title="Example"
395398
req := client.AcquireRequest()
396399
defer client.ReleaseRequest(req)
@@ -407,9 +410,6 @@ if err != nil {
407410
fmt.Println(string(resp.Body()))
408411
```
409412

410-
<details>
411-
<summary>Click here to see the result</summary>
412-
413413
```json
414414
{
415415
"Content-Length": "145",
@@ -459,6 +459,9 @@ It will override param, which has been set in client instance.
459459
func (r *Request) SetParamsWithStruct(v any) *Request
460460
```
461461

462+
<details>
463+
<summary>Example</summary>
464+
462465
```go title="Example"
463466
req := client.AcquireRequest()
464467
defer client.ReleaseRequest(req)
@@ -482,9 +485,6 @@ if err != nil {
482485
fmt.Println(string(resp.Body()))
483486
```
484487

485-
<details>
486-
<summary>Click here to see the result</summary>
487-
488488
```json
489489
{
490490
"Content-Length": "147",
@@ -591,6 +591,9 @@ It will override the cookie which is set in the client instance.
591591
func (r *Request) SetCookies(m map[string]string) *Request
592592
```
593593

594+
<details>
595+
<summary>Example</summary>
596+
594597
```go title="Example"
595598
req := client.AcquireRequest()
596599
defer client.ReleaseRequest(req)
@@ -608,9 +611,6 @@ if err != nil {
608611
fmt.Println(string(resp.Body()))
609612
```
610613

611-
<details>
612-
<summary>Click here to see the result</summary>
613-
614614
```json
615615
{
616616
"cookies": {
@@ -663,6 +663,9 @@ It will override path param which set in client instance.
663663
func (r *Request) SetPathParam(key, val string) *Request
664664
```
665665

666+
<details>
667+
<summary>Example</summary>
668+
666669
```go title="Example"
667670
req := client.AcquireRequest()
668671
defer client.ReleaseRequest(req)
@@ -677,9 +680,6 @@ if err != nil {
677680
fmt.Println(string(resp.Body()))
678681
```
679682

680-
<details>
681-
<summary>Click here to see the result</summary>
682-
683683
```plaintext
684684
Gofiber
685685
```
@@ -777,6 +777,9 @@ AddFormData method adds a single form data field and its value in the request in
777777
func (r *Request) AddFormData(key, val string) *Request
778778
```
779779

780+
<details>
781+
<summary>Example</summary>
782+
780783
```go title="Example"
781784
req := client.AcquireRequest()
782785
defer client.ReleaseRequest(req)
@@ -793,9 +796,6 @@ if err != nil {
793796
fmt.Println(string(resp.Body()))
794797
```
795798

796-
<details>
797-
<summary>Click here to see the result</summary>
798-
799799
```json
800800
{
801801
"args": {},
@@ -822,6 +822,9 @@ SetFormData method sets a single form data field and its value in the request in
822822
func (r *Request) SetFormData(key, val string) *Request
823823
```
824824

825+
<details>
826+
<summary>Example</summary>
827+
825828
```go title="Example"
826829
req := client.AcquireRequest()
827830
defer client.ReleaseRequest(req)
@@ -837,9 +840,6 @@ if err != nil {
837840
fmt.Println(string(resp.Body()))
838841
```
839842

840-
<details>
841-
<summary>Click here to see the result</summary>
842-
843843
```json
844844
{
845845
"args": {},
@@ -929,6 +929,9 @@ AddFile method adds a single file field and its value in the request instance vi
929929
func (r *Request) AddFile(path string) *Request
930930
```
931931

932+
<details>
933+
<summary>Example</summary>
934+
932935
```go title="Example"
933936
req := client.AcquireRequest()
934937
defer client.ReleaseRequest(req)
@@ -943,9 +946,6 @@ if err != nil {
943946
fmt.Println(string(resp.Body()))
944947
```
945948

946-
<details>
947-
<summary>Click here to see the result</summary>
948-
949949
```json
950950
{
951951
"args": {},
@@ -968,6 +968,9 @@ AddFileWithReader method adds a single field and its value in the request instan
968968
func (r *Request) AddFileWithReader(name string, reader io.ReadCloser) *Request
969969
```
970970

971+
<details>
972+
<summary>Example</summary>
973+
971974
```go title="Example"
972975
req := client.AcquireRequest()
973976
defer client.ReleaseRequest(req)
@@ -983,9 +986,6 @@ if err != nil {
983986
fmt.Println(string(resp.Body()))
984987
```
985988

986-
<details>
987-
<summary>Click here to see the result</summary>
988-
989989
```json
990990
{
991991
"args": {},
@@ -1025,6 +1025,9 @@ It will override timeout which set in client instance.
10251025
func (r *Request) SetTimeout(t time.Duration) *Request
10261026
```
10271027

1028+
<details>
1029+
<summary>Example 1</summary>
1030+
10281031
```go title="Example 1"
10291032
req := client.AcquireRequest()
10301033
defer client.ReleaseRequest(req)
@@ -1039,9 +1042,6 @@ if err != nil {
10391042
fmt.Println(string(resp.Body()))
10401043
```
10411044

1042-
<details>
1043-
<summary>Click here to see the result</summary>
1044-
10451045
```json
10461046
{
10471047
"args": {},
@@ -1054,6 +1054,9 @@ fmt.Println(string(resp.Body()))
10541054

10551055
</details>
10561056

1057+
<details>
1058+
<summary>Example 2</summary>
1059+
10571060
```go title="Example 2"
10581061
req := client.AcquireRequest()
10591062
defer client.ReleaseRequest(req)
@@ -1068,9 +1071,6 @@ if err != nil {
10681071
fmt.Println(string(resp.Body()))
10691072
```
10701073

1071-
<details>
1072-
<summary>Click here to see the result</summary>
1073-
10741074
```shell
10751075
panic: timeout or cancel
10761076

docs/client/response.md

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ Protocol method returns the HTTP response protocol used for the request.
6868
func (r *Response) Protocol() string
6969
```
7070

71+
<details>
72+
<summary>Example</summary>
73+
7174
```go title="Example"
7275
resp, err := client.Get("https://httpbin.org/get")
7376
if err != nil {
@@ -77,9 +80,6 @@ if err != nil {
7780
fmt.Println(resp.Protocol())
7881
```
7982

80-
<details>
81-
<summary>Click here to see the result</summary>
82-
8383
```text
8484
HTTP/1.1
8585
```
@@ -103,6 +103,9 @@ The returned value is valid until the response object is released. Any future ca
103103
func (r *Response) Headers() iter.Seq2[string, []string]
104104
```
105105

106+
<details>
107+
<summary>Example</summary>
108+
106109
```go title="Example"
107110
resp, err := client.Get("https://httpbin.org/get")
108111
if err != nil {
@@ -114,10 +117,6 @@ for key, values := range resp.Headers() {
114117
}
115118
```
116119

117-
<details>
118-
119-
<summary>Click here to see the result</summary>
120-
121120
```text
122121
Date => Wed, 04 Dec 2024 15:28:29 GMT
123122
Connection => keep-alive
@@ -127,6 +126,9 @@ Access-Control-Allow-Credentials => true
127126

128127
</details>
129128

129+
<details>
130+
<summary>Example with maps.Collect()</summary>
131+
130132
```go title="Example with maps.Collect()"
131133
resp, err := client.Get("https://httpbin.org/get")
132134
if err != nil {
@@ -139,10 +141,6 @@ for key, values := range headers {
139141
}
140142
```
141143

142-
<details>
143-
144-
<summary>Click here to see the result</summary>
145-
146144
```text
147145
Date => Wed, 04 Dec 2024 15:28:29 GMT
148146
Connection => keep-alive
@@ -161,6 +159,9 @@ The returned value is valid until the response object is released. Any future ca
161159
func (r *Response) Cookies() []*fasthttp.Cookie
162160
```
163161

162+
<details>
163+
<summary>Example</summary>
164+
164165
```go title="Example"
165166
resp, err := client.Get("https://httpbin.org/cookies/set/go/fiber")
166167
if err != nil {
@@ -173,9 +174,6 @@ for _, cookie := range cookies {
173174
}
174175
```
175176

176-
<details>
177-
<summary>Click here to see the result</summary>
178-
179177
```text
180178
go => fiber
181179
```
@@ -206,6 +204,9 @@ JSON method will unmarshal body to json.
206204
func (r *Response) JSON(v any) error
207205
```
208206

207+
<details>
208+
<summary>Example</summary>
209+
209210
```go title="Example"
210211
type Body struct {
211212
Slideshow struct {
@@ -229,9 +230,6 @@ if err != nil {
229230
fmt.Printf("%+v\n", out)
230231
```
231232

232-
<details>
233-
<summary>Click here to see the result</summary>
234-
235233
```text
236234
{Slideshow:{Author:Yours Truly Date:date of publication Title:Sample Slide Show}}
237235
```

0 commit comments

Comments
 (0)