Documentation ¶
Overview ¶
Utility package for Go that makes working with web services even easier.
Index ¶
- Variables
- func Delete(dest interface{}, uri string, data url.Values) error
- func Get(dest interface{}, uri string, data url.Values) error
- func Post(dest interface{}, uri string, data url.Values) error
- func PostMultipart(dest interface{}, uri string, data *MultipartBody) error
- func Put(dest interface{}, uri string, data url.Values) error
- func PutMultipart(dest interface{}, uri string, data *MultipartBody) error
- type Client
- func (self *Client) Delete(dst interface{}, path string, data url.Values) error
- func (self *Client) Get(dst interface{}, path string, data url.Values) error
- func (client *Client) GetHeader(header_name string) string
- func (client *Client) GetHeaders(path string) error
- func (self *Client) Post(dst interface{}, path string, data url.Values) error
- func (self *Client) PostMultipart(dst interface{}, uri string, data *MultipartBody) error
- func (self *Client) PostRaw(dst interface{}, path string, body []byte) error
- func (self *Client) Put(dst interface{}, path string, data url.Values) error
- func (self *Client) PutMultipart(dst interface{}, uri string, data *MultipartBody) error
- func (self *Client) SetBasicAuth(username string, password string)
- type File
- type MultipartBody
- type Response
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidPrefix is returned when attemping to create a New() client with // an invalid prefix. ErrInvalidPrefix = errors.New(`Expecting a valid canonical URL (http://...).`) // ErrCouldNotCreateMultipart is returned when attemping to create a // multipart request with a nil body. ErrCouldNotCreateMultipart = errors.New(`Couldn't create a multipart request without a body.`) // ErrCouldNotConvert is returned when the request response can't be // converted to the expected datatype. ErrCouldNotConvert = errors.New(`Could not convert response %s to %s.`) // ErrDestinationNotAPointer is returned when attemping to provide a // destination that is not a pointer. ErrDestinationNotAPointer = errors.New(`Destination is not a pointer.`) )
var DefaultClient = new(Client)
DefaulClient is the default client used on top level functions like rest.Get(), rest.Post(), rest.Delete() and rest.Put().
Functions ¶
func Delete ¶
Delete performs a HTTP DELETE request using the default client and, when complete, attempts to convert the response body into the datatype given by dst (a pointer to a struct, map or []byte array).
func Get ¶
Get performs a HTTP GET request using the default client and, when complete, attempts to convert the response body into the datatype given by dst (a pointer to a struct, map or []byte array).
func Post ¶
Post performs a HTTP POST request using the default client and, when complete, attempts to convert the response body into the datatype given by dst (a pointer to a struct, map or []byte array).
func PostMultipart ¶
func PostMultipart(dest interface{}, uri string, data *MultipartBody) error
PostMultipart performs a HTTP POST multipart request using the default client and, when complete, attempts to convert the response body into the datatype given by dst (a pointer to a struct, map or []byte array).
func Put ¶
Put performs a HTTP PUT request using the default client and, when complete, attempts to convert the response body into the datatype given by dst (a pointer to a struct, map or []byte array).
func PutMultipart ¶
func PutMultipart(dest interface{}, uri string, data *MultipartBody) error
PutMultipart performs a HTTP PUT multipart request using the default client and, when complete, attempts to convert the response body into the datatype given by dst (a pointer to a struct, map or []byte array).
Types ¶
type Client ¶
Client is useful in case you need to communicate with an API and you'd like to use the same prefix for all of your requests or in scenarios where it would be handy to keep a session cookie.
func New ¶
New creates a new client, in all following GET, POST, PUT and DELETE requests given paths will be prefixed with the given client's prefix value.
func (*Client) Delete ¶
Delete performs a HTTP DELETE request and, when complete, attempts to convert the response body into the datatype given by dst (a pointer to a struct, map or []byte array).
func (*Client) Get ¶
Get performs a HTTP GET request and, when complete, attempts to convert the response body into the datatype given by dst (a pointer to a struct, map or []byte array).
func (*Client) GetHeader ¶
Sets the request's basic authorization header to be used in all requests.
func (*Client) GetHeaders ¶
We don't need any GET vars We also don't care about the response body
func (*Client) Post ¶
Post performs a HTTP POST request and, when complete, attempts to convert the response body into the datatype given by dst (a pointer to a struct, map or []byte array).
func (*Client) PostMultipart ¶
func (self *Client) PostMultipart(dst interface{}, uri string, data *MultipartBody) error
PostMultipart performs a HTTP POST multipart request and, when complete, attempts to convert the response body into the datatype given by dst (a pointer to a struct, map or []byte array).
func (*Client) PostRaw ¶
PostRaw performs a HTTP POST request with a custom body and, when complete, attempts to convert the response body into the datatype given by dst (a pointer to a struct, map or []byte array).
func (*Client) Put ¶
Put performs a HTTP PUT request and, when complete, attempts to convert the response body into the datatype given by dst (a pointer to a struct, map or []byte array).
func (*Client) PutMultipart ¶
func (self *Client) PutMultipart(dst interface{}, uri string, data *MultipartBody) error
PutMultipart performs a HTTP PUT multipart request and, when complete, attempts to convert the response body into the datatype given by dst (a pointer to a struct, map or []byte array).
func (*Client) SetBasicAuth ¶
Sets the request's basic authorization header to be used in all requests.
type File ¶
File can be used to represent a file that you'll later upload within a multipart request.
type MultipartBody ¶
type MultipartBody struct {
// contains filtered or unexported fields
}
MultipartBody struct for multipart requests, you can't generate a MultipartBody directly, use rest.NewMultipartBody() instead.
func NewMultipartBody ¶
NewMultipartBody creates a *MultipartBody based on the given parameters. This is useful for PostMultipart() and PutMultipart().