github.com/newrelic/newrelic-client-go@v1.1.0/docs/internal/http/README.md (about) 1 # http 2 -- 3 import "." 4 5 6 ## Usage 7 8 ```go 9 var ( 10 // ErrNotFound is returned when the resource was not found in New Relic. 11 ErrNotFound = errors.New("newrelic: Resource not found") 12 ) 13 ``` 14 15 #### func RetryPolicy 16 17 ```go 18 func RetryPolicy(ctx context.Context, resp *http.Response, err error) (bool, error) 19 ``` 20 RetryPolicy provides a callback for retryablehttp's CheckRetry, which will retry 21 on connection errors and server errors. 22 23 #### type DefaultErrorResponse 24 25 ```go 26 type DefaultErrorResponse struct { 27 ErrorDetail ErrorDetail `json:"error"` 28 } 29 ``` 30 31 DefaultErrorResponse represents the default error response from New Relic. 32 33 #### func (*DefaultErrorResponse) Error 34 35 ```go 36 func (e *DefaultErrorResponse) Error() string 37 ``` 38 39 #### type ErrorDetail 40 41 ```go 42 type ErrorDetail struct { 43 Title string `json:"title"` 44 Messages []string `json:"messages"` 45 } 46 ``` 47 48 ErrorDetail represents a New Relic response error detail. 49 50 #### type ErrorNotFound 51 52 ```go 53 type ErrorNotFound struct{} 54 ``` 55 56 ErrorNotFound is returned when a 404 response is returned from New Relic's APIs. 57 58 #### func (*ErrorNotFound) Error 59 60 ```go 61 func (e *ErrorNotFound) Error() string 62 ``` 63 64 #### type ErrorResponse 65 66 ```go 67 type ErrorResponse interface { 68 Error() string 69 } 70 ``` 71 72 ErrorResponse provides an interface for obtaining a single error message from an 73 error response object. 74 75 #### type ErrorUnexpectedStatusCode 76 77 ```go 78 type ErrorUnexpectedStatusCode struct { 79 } 80 ``` 81 82 ErrorUnexpectedStatusCode is returned when an unexpected status code is returned 83 from New Relic's APIs. 84 85 #### func (*ErrorUnexpectedStatusCode) Error 86 87 ```go 88 func (e *ErrorUnexpectedStatusCode) Error() string 89 ``` 90 91 #### type LinkHeaderPager 92 93 ```go 94 type LinkHeaderPager struct{} 95 ``` 96 97 LinkHeaderPager represents a pagination implementation that adheres to RFC 5988. 98 99 #### func (*LinkHeaderPager) Parse 100 101 ```go 102 func (l *LinkHeaderPager) Parse(resp *http.Response) Paging 103 ``` 104 Parse is used to parse a pagination context from an HTTP response. 105 106 #### type NewRelicClient 107 108 ```go 109 type NewRelicClient struct { 110 Client *retryablehttp.Client 111 Config config.Config 112 } 113 ``` 114 115 NewRelicClient represents a client for communicating with the New Relic APIs. 116 117 #### func NewClient 118 119 ```go 120 func NewClient(config config.Config) NewRelicClient 121 ``` 122 NewClient is used to create a new instance of NewRelicClient. 123 124 #### func NewTestAPIClient 125 126 ```go 127 func NewTestAPIClient(handler http.Handler) NewRelicClient 128 ``` 129 NewTestAPIClient returns a test NewRelicClient instance that is configured to 130 communicate with a mock server. 131 132 #### func (*NewRelicClient) Delete 133 134 ```go 135 func (c *NewRelicClient) Delete(url string, 136 queryParams *map[string]string, 137 respBody interface{}, 138 ) (*http.Response, error) 139 ``` 140 Delete represents an HTTP DELETE request to a New Relic API. The queryParams 141 argument can be used to add query string parameters to the requested URL. The 142 respBody argument will be unmarshaled from JSON in the response body to the type 143 provided. If respBody is not nil and the response body cannot be unmarshaled to 144 the type provided, an error will be returned. 145 146 #### func (*NewRelicClient) Get 147 148 ```go 149 func (c *NewRelicClient) Get( 150 url string, 151 queryParams *map[string]string, 152 respBody interface{}, 153 ) (*http.Response, error) 154 ``` 155 Get represents an HTTP GET request to a New Relic API. The queryParams argument 156 can be used to add query string parameters to the requested URL. The respBody 157 argument will be unmarshaled from JSON in the response body to the type 158 provided. If respBody is not nil and the response body cannot be unmarshaled to 159 the type provided, an error will be returned. 160 161 #### func (*NewRelicClient) Post 162 163 ```go 164 func (c *NewRelicClient) Post( 165 url string, 166 params *map[string]string, 167 reqBody interface{}, 168 respBody interface{}, 169 ) (*http.Response, error) 170 ``` 171 Post represents an HTTP POST request to a New Relic API. The queryParams 172 argument can be used to add query string parameters to the requested URL. The 173 reqBody argument will be marshaled to JSON from the type provided and included 174 in the request body. The respBody argument will be unmarshaled from JSON in the 175 response body to the type provided. If respBody is not nil and the response body 176 cannot be unmarshaled to the type provided, an error will be returned. 177 178 #### func (*NewRelicClient) Put 179 180 ```go 181 func (c *NewRelicClient) Put( 182 url string, 183 queryParams *map[string]string, 184 reqBody interface{}, 185 respBody interface{}, 186 ) (*http.Response, error) 187 ``` 188 Put represents an HTTP PUT request to a New Relic API. The queryParams argument 189 can be used to add query string parameters to the requested URL. The reqBody 190 argument will be marshaled to JSON from the type provided and included in the 191 request body. The respBody argument will be unmarshaled from JSON in the 192 response body to the type provided. If respBody is not nil and the response body 193 cannot be unmarshaled to the type provided, an error will be returned. 194 195 #### func (*NewRelicClient) SetErrorValue 196 197 ```go 198 func (c *NewRelicClient) SetErrorValue(v ErrorResponse) *NewRelicClient 199 ``` 200 SetErrorValue is used to unmarshal error body responses in JSON format. 201 202 #### type Pager 203 204 ```go 205 type Pager interface { 206 Parse(res *http.Response) Paging 207 } 208 ``` 209 210 Pager represents a pagination implementation. 211 212 #### type Paging 213 214 ```go 215 type Paging struct { 216 Next string 217 } 218 ``` 219 220 Paging represents the pagination context returned from the Pager implementation.