Documentation ¶
Index ¶
- type APIError
- type BodyProvider
- type Doer
- type Nougat
- func (r *Nougat) Add(key, value string) *Nougat
- func (r *Nougat) Base(rawURL string) *Nougat
- func (r *Nougat) Body(body io.Reader) *Nougat
- func (r *Nougat) BodyForm(bodyForm interface{}) *Nougat
- func (r *Nougat) BodyJSON(bodyJSON interface{}) *Nougat
- func (r *Nougat) BodyProvider(body BodyProvider) *Nougat
- func (r *Nougat) Client(httpClient *http.Client) *Nougat
- func (r *Nougat) Connect(pathURL string) *Nougat
- func (r *Nougat) Delete(pathURL string) *Nougat
- func (r *Nougat) Do(req *http.Request, successV, failureV interface{}) (*http.Response, error)
- func (r *Nougat) Doer(doer Doer) *Nougat
- func (r *Nougat) Get(pathURL string) *Nougat
- func (r *Nougat) Head(pathURL string) *Nougat
- func (r *Nougat) New() *Nougat
- func (r *Nougat) Options(pathURL string) *Nougat
- func (r *Nougat) Patch(pathURL string) *Nougat
- func (r *Nougat) Path(path string) *Nougat
- func (r *Nougat) Post(pathURL string) *Nougat
- func (r *Nougat) Put(pathURL string) *Nougat
- func (r *Nougat) QueryStruct(queryStruct interface{}) *Nougat
- func (r *Nougat) Receive(successV, failureV interface{}) (*http.Response, error)
- func (r *Nougat) ReceiveSuccess(successV interface{}) (*http.Response, error)
- func (r *Nougat) Request() (*http.Request, error)
- func (r *Nougat) ResponseDecoder(decoder ResponseDecoder) *Nougat
- func (r *Nougat) Set(key, value string) *Nougat
- func (r *Nougat) SetBasicAuth(username, password string) *Nougat
- func (r *Nougat) Trace(pathURL string) *Nougat
- type ResponseDecoder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BodyProvider ¶
type Doer ¶
Doer executes http requests. It is implemented by *http.Client. You can wrap *http.Client with layers of Doers to form a stack of client-side middleware.
type Nougat ¶
type Nougat struct {
// contains filtered or unexported fields
}
Nougat is an HTTP Request builder and sender.
func (*Nougat) Add ¶
Add adds the key, value pair in Headers, appending values for existing keys to the key's values. Header keys are canonicalized.
func (*Nougat) Base ¶
Base sets the rawURL. If you intend to extend the url with Path, baseUrl should be specified with a trailing slash.
func (*Nougat) Body ¶
Body sets the Nougat's body. The body value will be set as the Body on new requests (see Request()). If the provided body is also an io.Closer, the request Body will be closed by http.Client methods.
func (*Nougat) BodyForm ¶
BodyForm sets the Nougat's bodyForm. The value pointed to by the bodyForm will be url encoded as the Body on new requests (see Request()). The bodyForm argument should be a pointer to a url tagged struct. See https://godoc.org/github.com/google/go-querystring/query for details.
func (*Nougat) BodyJSON ¶
BodyJSON sets the Nougat's bodyJSON. The value pointed to by the bodyJSON will be JSON encoded as the Body on new requests (see Request()). The bodyJSON argument should be a pointer to a JSON tagged struct. See https://golang.org/pkg/encoding/json/#MarshalIndent for details.
func (*Nougat) BodyProvider ¶
func (r *Nougat) BodyProvider(body BodyProvider) *Nougat
BodyProvider sets the Nougat's body provider.
func (*Nougat) Client ¶
Client sets the http Client used to do requests. If a nil client is given, the http.DefaultClient will be used.
func (*Nougat) Do ¶
Do sends an HTTP request and returns the response. Success responses (2XX) are JSON decoded into the value pointed to by successV and other responses are JSON decoded into the value pointed to by failureV. If the status code of response is 204(no content), decoding is skipped. Any error sending the request or decoding the response is returned.
func (*Nougat) Doer ¶
Doer sets the custom Doer implementation used to do requests. If a nil client is given, the http.DefaultClient will be used.
func (*Nougat) New ¶
New returns a copy of a Nougat for creating a new Nougat with properties from a parent Nougat. For example,
parentNougat := Nougat.New().Client(client).Base("https://api.io/") fooNougat := parentNougat.New().Get("foo/") barNougat := parentNougat.New().Get("bar/")
fooNougat and barNougat will both use the same client, but send requests to https://api.io/foo/ and https://api.io/bar/ respectively.
Note that query and body values are copied so if pointer values are used, mutating the original value will mutate the value within the child Nougat.
func (*Nougat) Path ¶
Path extends the rawURL with the given path by resolving the reference to an absolute URL. If parsing errors occur, the rawURL is left unmodified.
func (*Nougat) QueryStruct ¶
QueryStruct appends the queryStruct to the Nougat's queryStructs. The value pointed to by each queryStruct will be encoded as url query parameters on new requests (see Request()). The queryStruct argument should be a pointer to a url tagged struct. See https://godoc.org/github.com/google/go-querystring/query for details.
func (*Nougat) Receive ¶
Receive creates a new HTTP request and returns the response. Success responses (2XX) are JSON decoded into the value pointed to by successV and other responses are JSON decoded into the value pointed to by failureV. If the status code of response is 204(no content), decoding is skipped. Any error creating the request, sending it, or decoding the response is returned. Receive is shorthand for calling Request and Do.
func (*Nougat) ReceiveSuccess ¶
ReceiveSuccess creates a new HTTP request and returns the response. Success responses (2XX) are JSON decoded into the value pointed to by successV. Any error creating the request, sending it, or decoding a 2XX response is returned.
func (*Nougat) Request ¶
Request returns a new http.Request created with the Nougat properties. Returns any errors parsing the rawURL, encoding query structs, encoding the body, or creating the http.Request.
func (*Nougat) ResponseDecoder ¶
func (r *Nougat) ResponseDecoder(decoder ResponseDecoder) *Nougat
ResponseDecoder sets the Nougat's response decoder.
func (*Nougat) Set ¶
Set sets the key, value pair in Headers, replacing existing values associated with key. Header keys are canonicalized.
func (*Nougat) SetBasicAuth ¶
SetBasicAuth sets the Authorization header to use HTTP Basic Authentication with the provided username and password. With HTTP Basic Authentication the provided username and password are not encrypted.
type ResponseDecoder ¶
ResponseDecoder decodes http responses into struct values.