Documentation ¶
Index ¶
- type HttpClient
- func (httpClient *HttpClient) Delete(url string, headers map[string]string) (*http.Response, error)
- func (httpClient *HttpClient) Get(url string, headers map[string]string, out interface{}) (*http.Response, error)
- func (httpClient *HttpClient) Post(url string, headers map[string]string, in interface{}, out interface{}) (*http.Response, error)
- func (httpClient *HttpClient) PostJson(url string, headers map[string]string, in interface{}, out interface{}) (*http.Response, error)
- func (httpClient *HttpClient) Put(url string, headers map[string]string, in interface{}, out interface{}) (*http.Response, error)
- func (httpClient *HttpClient) PutJson(url string, headers map[string]string, in interface{}, out interface{}) (*http.Response, error)
- type HttpClientIface
- type HttpClientStub
- func (c *HttpClientStub) Delete(url string, headers map[string]string) (*http.Response, error)
- func (c *HttpClientStub) Get(url string, headers map[string]string, out interface{}) (*http.Response, error)
- func (c *HttpClientStub) Post(url string, headers map[string]string, in interface{}, out interface{}) (*http.Response, error)
- func (c *HttpClientStub) PostJson(url string, headers map[string]string, in interface{}, out interface{}) (*http.Response, error)
- func (c *HttpClientStub) Put(url string, headers map[string]string, in interface{}, out interface{}) (*http.Response, error)
- func (c *HttpClientStub) PutJson(url string, headers map[string]string, in interface{}, out interface{}) (*http.Response, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HttpClient ¶
HttpClient represents an http wrapper which reduces the boiler plate needed to marshall/un-marshall request/response bodies by providing friendly CRUD http operations that allow in/out interfaces
func (*HttpClient) Delete ¶
Delete issues a DELETE HTTP request to the specified URL including the headers passed in.
func (*HttpClient) Get ¶
func (httpClient *HttpClient) Get(url string, headers map[string]string, out interface{}) (*http.Response, error)
Get issues a GET HTTP request to the specified URL including the headers passed in.
The 'out' param interface is the un-marshall representation of the http response returned
Example on how to invoke the method:
type Out struct { Id string `json:"id"` Name string `json:"name"` Description string `json:"description"` } out := &Out{} headers := map[string]string{"header_example": "header_value"} HttpClient.Get("http://api.com/resource", headers, out)
func (*HttpClient) Post ¶
func (httpClient *HttpClient) Post(url string, headers map[string]string, in interface{}, out interface{}) (*http.Response, error)
Post issues a POST HTTP request to the specified URL including the headers passed in.
The in interface is marshall and added to the htp request body. The out interface is the un-marshall representation of the http response returned
Example on how to invoke the method:
type In struct { Name string `json:"name"` Description string `json:"description"` } type Out struct { Id string `json:"id"` Name string `json:"name"` Description string `json:"description"` } in := &In{} out := &Out{} headers := map[string]string{"header_example": "header_value"} HttpClient.Post("http://api.com/resource", headers, in, out)
func (*HttpClient) PostJson ¶
func (httpClient *HttpClient) PostJson(url string, headers map[string]string, in interface{}, out interface{}) (*http.Response, error)
PostJson issues a POST to the specified URL including the headers passed in. The content type of the body is set to application/json so it doesn't need to be added to the headers passed in
The 'in' param interface is marshall and added to the htp request body. The 'out' param interface is the un-marshall representation of the http response returned
Example on how to invoke the method:
type In struct { Name string `json:"name"` Description string `json:"description"` } type Out struct { Id string `json:"id"` Name string `json:"name"` Description string `json:"description"` } in := &In{} out := &Out{} headers := map[string]string{"header_example": "header_value"} HttpClient.PostJson("http://api.com/resource", headers, in, out)
func (*HttpClient) Put ¶
func (httpClient *HttpClient) Put(url string, headers map[string]string, in interface{}, out interface{}) (*http.Response, error)
Post issues a PUT HTTP request to the specified URL including the headers passed in.
The in interface is marshall and added to the http request body. The out interface is the un-marshall representation of the http response returned
Example on how to invoke the method:
type In struct { Name string `json:"name"` Description string `json:"description"` } type Out struct { Id string `json:"id"` Name string `json:"name"` Description string `json:"description"` } in := &In{} out := &Out{} headers := map[string]string{"header_example": "header_value"} HttpClient.Put("http://api.com/resource", headers, in, out)
func (*HttpClient) PutJson ¶
func (httpClient *HttpClient) PutJson(url string, headers map[string]string, in interface{}, out interface{}) (*http.Response, error)
PutJson issues a PUT HTTP request to the specified URL including the headers passed in. The content type of the body is set to application/json
The 'in' param interface is marshall and added to the htp request body. The 'out' param interface is the un-marshall representation of the http response returned
Example on how to invoke the method:
type In struct { Name string `json:"name"` Description string `json:"description"` } type Out struct { Id string `json:"id"` Name string `json:"name"` Description string `json:"description"` } in := &In{} out := &Out{} headers := map[string]string{"header_example": "header_value"} HttpClient.PutJson("http://api.com/resource", headers, in, out)
type HttpClientIface ¶
type HttpClientIface interface { Get(url string, headers map[string]string, out interface{}) (*http.Response, error) PostJson(url string, headers map[string]string, in interface{}, out interface{}) (*http.Response, error) Post(url string, headers map[string]string, in interface{}, out interface{}) (*http.Response, error) PutJson(url string, headers map[string]string, in interface{}, out interface{}) (*http.Response, error) Put(url string, headers map[string]string, in interface{}, out interface{}) (*http.Response, error) Delete(url string, headers map[string]string) (*http.Response, error) }
type HttpClientStub ¶
type HttpClientStub struct { // Properties that tests can run assertions against to URL string Headers map[string]string In interface{} Out interface{} // Stub response Response *http.Response // Stub error Error error }
HttpClientStub implements the HttpClientIface and should be used for unit testing purposes