Documentation ¶
Overview ¶
Package napping is a client library for interacting with RESTful APIs.
Example:
type Foo struct { Bar string } type Spam struct { Eggs int } payload := Foo{ Bar: "baz", } result := Spam{} url := "http://foo.com/bar" resp, err := napping.Post(url, &payload, &result, nil) if err != nil { panic(err) } if resp.Status() == 200 { println(result.Eggs) }
See the "examples" folder for a more complete example.
Index ¶
- type Params
- type Request
- type Response
- func Delete(url string, p *url.Values, result, errMsg interface{}) (*Response, error)
- func Get(url string, p *url.Values, result, errMsg interface{}) (*Response, error)
- func Head(url string, result, errMsg interface{}) (*Response, error)
- func Options(url string, result, errMsg interface{}) (*Response, error)
- func Patch(url string, payload, result, errMsg interface{}) (*Response, error)
- func Post(url string, payload, result, errMsg interface{}) (*Response, error)
- func Put(url string, payload, result, errMsg interface{}) (*Response, error)
- func Send(r *Request) (*Response, error)
- type Session
- func (s *Session) Delete(url string, p *url.Values, result, errMsg interface{}) (*Response, error)
- func (s *Session) Get(url string, p *url.Values, result, errMsg interface{}) (*Response, error)
- func (s *Session) Head(url string, result, errMsg interface{}) (*Response, error)
- func (s *Session) Options(url string, result, errMsg interface{}) (*Response, error)
- func (s *Session) Patch(url string, payload, result, errMsg interface{}) (*Response, error)
- func (s *Session) Post(url string, payload, result, errMsg interface{}) (*Response, error)
- func (s *Session) Put(url string, payload, result, errMsg interface{}) (*Response, error)
- func (s *Session) Send(r *Request) (response *Response, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Request ¶
type Request struct { Url string // Raw URL string Method string // HTTP method to use Params *url.Values // URL query parameters Payload interface{} // Data to JSON-encode and POST // Can be set to true if Payload is of type *bytes.Buffer and client wants // to send it as-is RawPayload bool // Result is a pointer to a data structure. On success (HTTP status < 300), // response from server is unmarshaled into Result. Result interface{} // CaptureResponseBody can be set to capture the response body for external use. CaptureResponseBody bool // ResponseBody exports the raw response body if CaptureResponseBody is true. ResponseBody *bytes.Buffer // Error is a pointer to a data structure. On error (HTTP status >= 300), // response from server is unmarshaled into Error. Error interface{} // Optional Userinfo *url.Userinfo Header *http.Header // contains filtered or unexported fields }
A Request describes an HTTP request to be executed, data structures into which the result will be unmarshalled, and the server's response. By using a single object for both the request and the response we allow easy access to Result and Error objects without needing type assertions.
type Response ¶
type Response Request
A Response is a Request object that has been executed.
func (*Response) HttpResponse ¶
HttpResponse returns the underlying Response object from http package.
func (*Response) Status ¶
Status returns the HTTP status for the executed request, or 0 if request has not yet been sent.
type Session ¶
type Session struct { Client *http.Client Log bool // Log request and response // Optional Userinfo *url.Userinfo // Optional defaults - can be overridden in a Request Header *http.Header Params *url.Values }
Directories ¶
Path | Synopsis |
---|---|
examples
|
|
github_auth_token
Example demonstrating use of package napping, with HTTP Basic authentictation over HTTPS, to retrieve a Github auth token.
|
Example demonstrating use of package napping, with HTTP Basic authentictation over HTTPS, to retrieve a Github auth token. |