pull/882/merge
Ganesh Bhambarkar 2025-11-24 21:24:58 +07:00 committed by GitHub
commit 6e0a2d14a1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 1 deletions

@ -1571,6 +1571,7 @@ Examples:
| Name | Type | Required | Default |
| ---- | ---- | -------- | ------- |
| url | string | no | |
| host | string | no | |
| headers | key (string) & value (string) | no | |
| method | string | no | GET |
| body-type | string | no | json |
@ -1595,6 +1596,9 @@ headers:
Accept: application/json
```
##### `host`
Optionally specify the `Host` header that will be sent with the request. This is useful when `url` points to a reverse proxy. Note that setting the `Host` header in `headers` has no effect.
##### `method`
The HTTP method to use when making the request. Possible values are `GET`, `POST`, `PUT`, `PATCH`, `DELETE`, `OPTIONS` and `HEAD`.

@ -410,7 +410,7 @@ In some instances, you may need to make two consecutive API calls, where you use
{{ $something.JSON.String "title" }}
```
Here, `$theID` gets retrieved from the result of the first API call and used in the second API call. The `newRequest` function creates a new request, and the `getResponse` function executes it. You can also use `withParameter` and `withHeader` to optionally add parameters and headers to the request.
Here, `$theID` gets retrieved from the result of the first API call and used in the second API call. The `newRequest` function creates a new request, and the `getResponse` function executes it. You can also use `withParameter` and `withHeader` to optionally add parameters and headers to the request. Note that `Host` header added using `withHeader` has no effect. You can use `withHost` to set the `Host` header.
If you need to make a request to a URL that requires dynamic parameters, you can omit the `url` property in the YAML and run the request entirely from within the template itself:

@ -30,6 +30,7 @@ type CustomAPIRequest struct {
URL string `yaml:"url"`
AllowInsecure bool `yaml:"allow-insecure"`
Headers map[string]string `yaml:"headers"`
Host string `yaml:"host"`
Parameters queryParametersField `yaml:"parameters"`
Method string `yaml:"method"`
BodyType string `yaml:"body-type"`
@ -182,6 +183,10 @@ func (req *CustomAPIRequest) initialize() error {
return err
}
if req.Host != "" {
httpReq.Host = req.Host
}
if len(req.Parameters) > 0 {
httpReq.URL.RawQuery = req.Parameters.toQueryString()
}
@ -690,6 +695,10 @@ var customAPITemplateFuncs = func() template.FuncMap {
req.Headers[key] = value
return req
},
"withHost": func(value string, req *CustomAPIRequest) *CustomAPIRequest {
req.Host = value
return req
},
"withParameter": func(key, value string, req *CustomAPIRequest) *CustomAPIRequest {
if req.Parameters == nil {
req.Parameters = make(queryParametersField)