You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/en/functions/resources/GetRemote.md
+57-37Lines changed: 57 additions & 37 deletions
Original file line number
Diff line number
Diff line change
@@ -35,6 +35,38 @@ toc: true
35
35
36
36
The `resources.GetRemote` function takes an optional map of options.
37
37
38
+
###### body
39
+
40
+
(`string`) The data you want to transmit to the server.
41
+
42
+
###### headers
43
+
44
+
(`map[string][]string`) The collection of key-value pairs that provide additional information about the request.
45
+
46
+
###### key
47
+
48
+
(`string`) The cache key. Hugo derives the default value from the URL and options map. See [caching](#caching).
49
+
50
+
###### method
51
+
52
+
(`string`) The action to perform on the requested resource, typically one of `GET`, `POST`, or `HEAD`.
53
+
54
+
###### responseHeaders
55
+
56
+
(`[]string`) The headers to extract from the server's response, accessible through the resource's [`Data.Headers`] method. Header name matching is case-insensitive.
57
+
58
+
[`Data.Headers`]: /methods/resource/data/#headers
59
+
60
+
## Options examples
61
+
62
+
{{% note %}}
63
+
For brevity, the examples below do not include [error handling].
64
+
65
+
[error handling]: #error-handling
66
+
{{% /note %}}
67
+
68
+
To include a header:
69
+
38
70
```go-html-template
39
71
{{ $url := "https://example.org/api" }}
40
72
{{ $opts := dict
@@ -43,7 +75,7 @@ The `resources.GetRemote` function takes an optional map of options.
43
75
{{ $resource := resources.GetRemote $url $opts }}
44
76
```
45
77
46
-
If you need multiple values for the same header key, use a slice:
78
+
To specify more than one value for the same header key, use a slice:
47
79
48
80
```go-html-template
49
81
{{ $url := "https://example.org/api" }}
@@ -53,7 +85,7 @@ If you need multiple values for the same header key, use a slice:
53
85
{{ $resource := resources.GetRemote $url $opts }}
54
86
```
55
87
56
-
You can also change the request method and set the request body:
88
+
To post data:
57
89
58
90
```go-html-template
59
91
{{ $url := "https://example.org/api" }}
@@ -65,6 +97,27 @@ You can also change the request method and set the request body:
65
97
{{ $resource := resources.GetRemote $url $opts }}
66
98
```
67
99
100
+
To override the default cache key:
101
+
102
+
```go-html-template
103
+
{{ $url := "https://example.org/images/a.jpg" }}
104
+
{{ $opts := dict
105
+
"key" (print $url (now.Format "2006-01-02"))
106
+
}}
107
+
{{ $resource := resources.GetRemote $url $opts }}
108
+
```
109
+
110
+
To extract specific headers from the server's response:
@@ -34,19 +36,30 @@ The `Data` method on a resource returned by the [`resources.GetRemote`] function
34
36
{{ end }}
35
37
```
36
38
37
-
ContentLength
38
-
: (`int`) The content length in bytes.
39
+
###### ContentLength
39
40
40
-
ContentType
41
-
: (`string`) The content type.
41
+
(`int`) The content length in bytes.
42
42
43
-
Status
44
-
: (`string`) The HTTP status text.
43
+
###### ContentType
45
44
46
-
StatusCode
47
-
: (`int`) The HTTP status code.
45
+
(`string`) The content type.
48
46
49
-
TransferEncoding
50
-
: (`string`) The transfer encoding.
47
+
###### Headers
48
+
49
+
(`map[string][]string`) A map of response headers matching those requested in the [`responseHeaders`] option passed to the `resources.GetRemote` function. The header name matching is case-insensitive. In most cases there will be one value per header key.
0 commit comments