Skip to content

Commit 8104ce0

Browse files
authored
Merge pull request #9 from go-resty/docs-part8
Docs part8
2 parents fcbc523 + 0d8efbc commit 8104ce0

23 files changed

+902
-17
lines changed

content/docs/allow-payload-on.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ However, the methods GET and DELETE have been the subject of debate or interpret
99

1010
So Resty, by default, disallows the request payload on GET and DELETE HTTP verbs.
1111

12-
Some systems, in real-world use, request payloads on GET and DELETE. Resty provides explicit methods to enable payloads for these verbs.
12+
Some systems, in real-world use, request payloads on GET and DELETE. Resty provides explicit methods to enable payload for these verbs.
1313

1414
## Methods
1515

content/docs/authentication.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,4 @@ client.AddRequestMiddleware(func(c *resty.Client, req *resty.Request) error {
108108
* [Request.SetBasicAuth]({{% godoc v3 %}}Request.SetBasicAuth)
109109
* [Request.SetAuthToken]({{% godoc v3 %}}Request.SetAuthToken)
110110
* [Request.SetAuthScheme]({{% godoc v3 %}}Request.SetAuthScheme)
111+
* [Request.SetHeaderAuthorizationKey]({{% godoc v3 %}}Request.SetHeaderAuthorizationKey)

content/docs/client-certificates.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
weight: 6
2+
weight: 7
33
---
44

55
# Client Certificates

content/docs/client-root-certificates.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
weight: 5
2+
weight: 6
33
---
44

55
# Client Root Certificates

content/docs/content-type-encoder-and-decoder.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Content-Type {Encoder, Decoder}
3-
weight: 6
3+
weight: 7
44
---
55

66
# Content-Type {Encoder, Decoder}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
title: DELETE Request
3+
weight: 2
4+
---
5+
6+
# DELETE Request
7+
8+
This page discusses simple DELETE requests. Users can utilize Resty features across nearly all HTTP methods.
9+
10+
{{% hint info %}}
11+
* Explore the documentation to fulfill all use cases.
12+
* Examples use request-level methods; however, Resty also includes client-level methods to configure settings for all requests.
13+
{{% /hint %}}
14+
15+
## Examples
16+
17+
See [Request Body Types]({{% relref "request-body-types" %}}), [Allow Payload On]({{% relref "allow-payload-on" %}})
18+
19+
```go
20+
// create a Resty client
21+
client := resty.New()
22+
defer client.Close()
23+
```
24+
25+
### Simple
26+
27+
```go
28+
res, err := client.R().
29+
SetAuthToken("bc594900518b4f7eac75bd37f019e08fbc594900518b4f7eac75bd37f019e08f").
30+
SetError(&Error{}). // or SetError(Error{}).
31+
Delete("https://myapp.com/articles/123456")
32+
33+
fmt.Println(err, res)
34+
fmt.Println(res.Error().(*Error))
35+
```
36+
37+
### With Payload
38+
39+
See [Allow Payload On]({{% relref "allow-payload-on" %}})
40+
41+
```go
42+
res, err := client.R().
43+
SetAuthToken("bc594900518b4f7eac75bd37f019e08fbc594900518b4f7eac75bd37f019e08f").
44+
SetBody(map[string]any{
45+
"article_ids": []int{1002, 1006, 1007, 87683, 45432},
46+
}). // default request content type is JSON
47+
SetError(&Error{}). // or SetError(Error{}).
48+
Delete("https://myapp.com/articles")
49+
50+
fmt.Println(err, res)
51+
fmt.Println(res.Error().(*Error))
52+
```
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
---
2+
title: GET Request
3+
weight: 1
4+
---
5+
6+
# GET Request
7+
8+
This page discusses simple GET requests. Users can utilize Resty features across nearly all HTTP methods.
9+
10+
{{% hint info %}}
11+
* Explore the documentation to fulfill all use cases.
12+
* Examples use request-level methods; however, Resty also includes client-level methods to configure settings for all requests.
13+
{{% /hint %}}
14+
15+
## Examples
16+
17+
See [Request Body Types]({{% relref "request-body-types" %}}), [Allow Payload On]({{% relref "allow-payload-on" %}})
18+
19+
```go
20+
// create a Resty client
21+
client := resty.New()
22+
defer client.Close()
23+
```
24+
25+
### Simple
26+
27+
```go
28+
res, err := client.R().
29+
Get("https://httpbin.org/get")
30+
31+
fmt.Println(err, res)
32+
```
33+
34+
### With Query Params
35+
36+
See [Request Query Params]({{% relref "request-query-params" %}})
37+
38+
```go
39+
res, err := client.R().
40+
SetQueryParams(map[string]string{
41+
"page_no": "1",
42+
"limit": "20",
43+
"sort": "name",
44+
"order": "asc",
45+
"random": strconv.FormatInt(time.Now().Unix(), 10),
46+
}).
47+
SetHeader("Accept", "application/json").
48+
SetAuthToken("bc594900518b4f7eac75bd37f019e08fbc594900518b4f7eac75bd37f019e08f").
49+
Get("/search_result")
50+
51+
fmt.Println(err, res)
52+
```
53+
54+
### With Path Params
55+
56+
See [Request Path Params]({{% relref "request-path-params" %}})
57+
58+
```go
59+
res, err := client.R().
60+
SetPathParams(map[string]string{
61+
"userId": "sample@sample.com",
62+
"subAccountId": "100002",
63+
}).
64+
SetAuthToken("bc594900518b4f7eac75bd37f019e08fbc594900518b4f7eac75bd37f019e08f").
65+
Get("/v1/users/{userId}/{subAccountId}/details")
66+
67+
fmt.Println(err, res)
68+
```
69+
70+
### With Payload
71+
72+
See [Allow Payload On]({{% relref "allow-payload-on" %}})
73+
74+
```go
75+
res, err := client.R().
76+
SetAllowMethodGetPayload(true). // client level options is available
77+
SetContentType("application/json").
78+
SetBody(`{
79+
"query": {
80+
"simple_query_string" : {
81+
"query": "\"fried eggs\" +(eggplant | potato) -frittata",
82+
"fields": ["title^5", "body"],
83+
"default_operator": "and"
84+
}
85+
}
86+
}`). // this is string value as request body
87+
SetAuthToken("bc594900518b4f7eac75bd37f019e08fbc594900518b4f7eac75bd37f019e08f").
88+
Get("/_search")
89+
90+
fmt.Println(err, res)
91+
```

content/docs/example/oauth2-client-credentials.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ title: OAuth2 Client Credentials
77
[![Go Reference](https://pkg.go.dev/badge/golang.org/x/oauth2/clientcredentials.svg)](https://pkg.go.dev/golang.org/x/oauth2/clientcredentials)
88

99

10-
## Without Modifying TLSClientConfig
10+
## Without Modifying
1111

1212
{{% hint info %}}
1313
As per the GoDoc of [clientcredentials#Config.Client](https://pkg.go.dev/golang.org/x/oauth2/clientcredentials#Config.Client)
@@ -30,14 +30,14 @@ defer c.Close()
3030
```
3131

3232

33-
## Modifying TLSClientConfig
33+
## Modifying
3434

35-
This scenario is applicable for adding Root CA, Client Root CA, Client SSL certs, transport timeouts, etc.
35+
This scenario applies to any client and transport-related configurations, such as adding Root CA, Client Root CA, Client SSL certificates, transport timeouts, and so on.
3636

3737
{{% hint info %}}
3838
* As per the GoDoc of [clientcredentials#Config.Client](https://pkg.go.dev/golang.org/x/oauth2/clientcredentials#Config.Client)
3939
* The returned `Client` and its `Transport` should not be modified.
40-
* To modify TLSClientConfig and use the oauth2 client credentials package together, a slight tweak is required.
40+
* To use the oauth2 client credentials package and make modifications to it, a minor adjustment is necessary.
4141
{{% /hint %}}
4242

4343
```go
@@ -50,9 +50,9 @@ c := resty.New()
5050
defer c.Close()
5151

5252
// configure required Root CA, Client Root CA, or Client SSL certs
53-
c.SetRootCertificates("/path/to/root/pemFile.pem")
54-
c.SetClientRootCertificates("/path/to/client-root/pemFile.pem")
55-
c.SetCertificateFromFile("/path/to/certs/client.pem", "/path/to/certs/client.key")
53+
// c.SetRootCertificates("/path/to/root/pemFile.pem")
54+
// c.SetClientRootCertificates("/path/to/client-root/pemFile.pem")
55+
// c.SetCertificateFromFile("/path/to/certs/client.pem", "/path/to/certs/client.key")
5656

5757
// add custom auth request middleware
5858
c.AddRequestMiddleware(func(c *resty.Client, req *resty.Request) error {

content/docs/example/oauth2-clientcredentials-package.md

Whitespace-only changes.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
title: OPTIONS, HEAD, TRACE Request
3+
weight: 2
4+
---
5+
6+
# OPTIONS, HEAD, TRACE Request
7+
8+
This page discusses simple OPTIONS, HEAD, and TRACE requests. Users can utilize Resty features across nearly all HTTP methods.
9+
10+
{{% hint info %}}
11+
* Explore the documentation to fulfill all use cases.
12+
* Examples use request-level methods; however, Resty also includes client-level methods to configure settings for all requests.
13+
{{% /hint %}}
14+
15+
## Examples
16+
17+
```go
18+
// create a Resty client
19+
client := resty.New()
20+
defer client.Close()
21+
```
22+
23+
### OPTIONS
24+
25+
Commonly used to determine permitted HTTP methods or CORS preflight requests.
26+
27+
```go
28+
res, err := client.R().
29+
SetAuthToken("bc594900518b4f7eac75bd37f019e08fbc594900518b4f7eac75bd37f019e08f").
30+
Options("https://myapp.com/servers/nyc-dc-01")
31+
32+
fmt.Println(err, res)
33+
fmt.Println(res.Header())
34+
```
35+
36+
### HEAD
37+
38+
```go
39+
res, err = client.R().
40+
SetAuthToken("bc594900518b4f7eac75bd37f019e08fbc594900518b4f7eac75bd37f019e08f").
41+
Head("https://myapp.com/videos/hi-res-video")
42+
43+
fmt.Println(err, res)
44+
fmt.Println(res.Header())
45+
```
46+
47+
### TRACE
48+
49+
```go
50+
res, err = client.R().
51+
SetAuthToken("bc594900518b4f7eac75bd37f019e08fbc594900518b4f7eac75bd37f019e08f").
52+
Trace("https://myapp.com/test")
53+
54+
fmt.Println(err, res)
55+
```

0 commit comments

Comments
 (0)