Documentation ¶
Overview ¶
Package simplehttp provides some simple methods and types to do HTTP queries with form values and parameters easily - especially if the returned result is expected to be JSON or XML.
Author: Michael Banzon
Index ¶
- func GetJSONInput(r *http.Request, w http.ResponseWriter, v interface{}) (err error)
- func OutputJSON(w http.ResponseWriter, v interface{}) (err error)
- type BasicAuthentication
- type FormDataPayload
- type HTTPRequest
- func (r *HTTPRequest) AddHeader(name, value string)
- func (r *HTTPRequest) AddParameter(name, value string)
- func (r *HTTPRequest) GetResponseFromJSON(v interface{}) error
- func (r *HTTPRequest) MakeDeleteRequest() (*HTTPResponse, error)
- func (r *HTTPRequest) MakeGetRequest() (*HTTPResponse, error)
- func (r *HTTPRequest) MakePostRequest(payload Payload) (*HTTPResponse, error)
- func (r *HTTPRequest) MakePutRequest(payload Payload) (*HTTPResponse, error)
- func (r *HTTPRequest) MakeRequest(method string, payload Payload) (*HTTPResponse, error)
- func (r *HTTPRequest) PostResponseFromJSON(payload Payload, v interface{}) error
- func (r *HTTPRequest) SetBasicAuth(user, password string)
- func (r *HTTPRequest) SetClient(c *http.Client)
- type HTTPResponse
- type Payload
- type RawPayload
- type Request
- type UrlEncodedPayload
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetJSONInput ¶
func GetJSONInput(r *http.Request, w http.ResponseWriter, v interface{}) (err error)
func OutputJSON ¶
func OutputJSON(w http.ResponseWriter, v interface{}) (err error)
Types ¶
type BasicAuthentication ¶
Type to encapsulate basic authentication for requests.
type FormDataPayload ¶
type FormDataPayload struct { Values []keyValuePair Files []keyValuePair ReadClosers []keyNameRC // contains filtered or unexported fields }
func NewFormDataPayload ¶
func NewFormDataPayload() *FormDataPayload
func (*FormDataPayload) AddFile ¶
func (f *FormDataPayload) AddFile(key, file string)
func (*FormDataPayload) AddReadCloser ¶
func (f *FormDataPayload) AddReadCloser(key, name string, rc io.ReadCloser)
func (*FormDataPayload) AddValue ¶
func (f *FormDataPayload) AddValue(key, value string)
func (*FormDataPayload) GetContentType ¶
func (f *FormDataPayload) GetContentType() string
func (*FormDataPayload) GetPayloadBuffer ¶
func (f *FormDataPayload) GetPayloadBuffer() (*bytes.Buffer, error)
type HTTPRequest ¶
type HTTPRequest struct { URL string Parameters map[string][]string Headers map[string]string BasicAuthUser string BasicAuthPassword string Client *http.Client }
Holds all information used to make a HTTP request.
func NewHTTPRequest ¶
func NewHTTPRequest(url string) *HTTPRequest
Creates a new HTTPRequest instance.
func (*HTTPRequest) AddHeader ¶
func (r *HTTPRequest) AddHeader(name, value string)
Adds a header that will be sent with the HTTP request.
func (*HTTPRequest) AddParameter ¶
func (r *HTTPRequest) AddParameter(name, value string)
Adds a parameter to the generated query string.
func (*HTTPRequest) GetResponseFromJSON ¶
func (r *HTTPRequest) GetResponseFromJSON(v interface{}) error
func (*HTTPRequest) MakeDeleteRequest ¶
func (r *HTTPRequest) MakeDeleteRequest() (*HTTPResponse, error)
func (*HTTPRequest) MakeGetRequest ¶
func (r *HTTPRequest) MakeGetRequest() (*HTTPResponse, error)
func (*HTTPRequest) MakePostRequest ¶
func (r *HTTPRequest) MakePostRequest(payload Payload) (*HTTPResponse, error)
func (*HTTPRequest) MakePutRequest ¶
func (r *HTTPRequest) MakePutRequest(payload Payload) (*HTTPResponse, error)
func (*HTTPRequest) MakeRequest ¶
func (r *HTTPRequest) MakeRequest(method string, payload Payload) (*HTTPResponse, error)
func (*HTTPRequest) PostResponseFromJSON ¶
func (r *HTTPRequest) PostResponseFromJSON(payload Payload, v interface{}) error
func (*HTTPRequest) SetBasicAuth ¶
func (r *HTTPRequest) SetBasicAuth(user, password string)
Sets username and password for basic authentication.
func (*HTTPRequest) SetClient ¶
func (r *HTTPRequest) SetClient(c *http.Client)
type HTTPResponse ¶
func (*HTTPResponse) ParseFromJSON ¶
func (r *HTTPResponse) ParseFromJSON(v interface{}) error
Parses the HTTPResponse as JSON to the given interface.
func (*HTTPResponse) ParseFromXML ¶
func (r *HTTPResponse) ParseFromXML(v interface{}) error
type Payload ¶
type RawPayload ¶
type RawPayload struct {
Data []byte
}
func NewRawPayload ¶
func NewRawPayload(data []byte) *RawPayload
func (*RawPayload) GetContentType ¶
func (r *RawPayload) GetContentType() string
func (*RawPayload) GetPayloadBuffer ¶
func (r *RawPayload) GetPayloadBuffer() (*bytes.Buffer, error)
type Request ¶
type Request struct { Url string Authentication BasicAuthentication UserAgent string Data []byte }
Type to wrap requests.
type UrlEncodedPayload ¶
type UrlEncodedPayload struct {
Values []keyValuePair
}
func NewUrlEncodedPayload ¶
func NewUrlEncodedPayload() *UrlEncodedPayload
func (*UrlEncodedPayload) AddValue ¶
func (f *UrlEncodedPayload) AddValue(key, value string)
func (*UrlEncodedPayload) GetContentType ¶
func (f *UrlEncodedPayload) GetContentType() string
func (*UrlEncodedPayload) GetPayloadBuffer ¶
func (f *UrlEncodedPayload) GetPayloadBuffer() (*bytes.Buffer, error)
Click to show internal directories.
Click to hide internal directories.