bluemix-go: github.com/IBM-Cloud/bluemix-go/rest Index | Files

package rest

import "github.com/IBM-Cloud/bluemix-go/rest"

Sending request:

client := NewClient()
var foo = struct {
	Bar string
}{}
var apiErr = struct {
	Message string
}{}
resp, err := client.Do(request, &foo, &apiErr)

Index

Package Files

client.go request.go

Constants

const (
    //ErrCodeEmptyResponse ...
    ErrCodeEmptyResponse = "EmptyResponseBody"
)

Variables

var ErrEmptyResponseBody = bmxerror.New(ErrCodeEmptyResponse, "empty response body")

ErrEmptyResponseBody ...

type Client Uses

type Client struct {
    // The HTTP client to be used. Default is HTTP's defaultClient.
    HTTPClient *http.Client
    // Defaualt header for all outgoing HTTP requests.
    DefaultHeader http.Header
}

Client is a REST client. It's recommend that a client be created with the NewClient() method.

func NewClient Uses

func NewClient() *Client

NewClient creates a new REST client.

func (*Client) Do Uses

func (c *Client) Do(r *Request, respV interface{}, errV interface{}) (*http.Response, error)

Do sends an request and returns an HTTP response. The resp.Body will be consumed and closed in the method.

For 2XX response, it will be JSON decoded into the value pointed to by respv.

For non-2XX response, an attempt will be made to unmarshal the response into the value pointed to by errV. If unmarshal failed, an ErrorResponse error with status code and response text is returned.

type File Uses

type File struct {
    // File name
    Name string
    // File content
    Content io.Reader
    // Mime type, defaults to "application/octet-stream"
    Type string
}

File represents a file upload in the POST request

type Request Uses

type Request struct {
    // contains filtered or unexported fields
}

Request is a REST request. It also acts like a HTTP request builder.

func DeleteRequest Uses

func DeleteRequest(rawUrl string) *Request

DeleteRequest creates a REST request with DELETE method and the given rawUrl.

func GetRequest Uses

func GetRequest(rawUrl string) *Request

GetRequest creates a REST request with GET method and the given rawUrl.

func HeadRequest Uses

func HeadRequest(rawUrl string) *Request

HeadRequest creates a REST request with HEAD method and the given rawUrl.

func NewRequest Uses

func NewRequest(rawUrl string) *Request

NewRequest creates a new REST request with the given rawUrl.

func OptionsRequest Uses

func OptionsRequest(rawUrl string) *Request

Creates a request with HTTP OPTIONS.

func PatchRequest Uses

func PatchRequest(rawUrl string) *Request

PatchRequest creates a REST request with PATCH method and the given rawUrl.

func PostRequest Uses

func PostRequest(rawUrl string) *Request

PostRequest creates a REST request with POST method and the given rawUrl.

func PutRequest Uses

func PutRequest(rawUrl string) *Request

PutRequest creates a REST request with PUT method and the given rawUrl.

func (*Request) Add Uses

func (r *Request) Add(key string, value string) *Request

Add adds the key, value pair to the request header. It appends to any existing values associated with key.

func (*Request) Body Uses

func (r *Request) Body(body interface{}) *Request

Body sets the request body. Accepted types are string, []byte, io.Reader, or structs to be JSON encodeded.

func (*Request) Build Uses

func (r *Request) Build() (*http.Request, error)

Build builds a HTTP request according to the settings in the REST request.

func (*Request) Del Uses

func (r *Request) Del(key string) *Request

Del deletes the header as specified by the key.

func (*Request) Field Uses

func (r *Request) Field(key string, value string) *Request

Field appends the key, value pair to the form fields in the POST request.

func (*Request) File Uses

func (r *Request) File(name string, file File) *Request

File appends a file upload item in the POST request. The file content will be consumed when building HTTP request (see Build()) and closed if it's also a ReadCloser type.

func (*Request) Method Uses

func (r *Request) Method(method string) *Request

Method sets HTTP method of the request.

func (*Request) Query Uses

func (r *Request) Query(key string, value string) *Request

Query appends the key, value pair to the request query which will be encoded as url query parameters on HTTP request's url.

func (*Request) Set Uses

func (r *Request) Set(key string, value string) *Request

Set sets the header entries associated with key to the single element value. It replaces any existing values associated with key.

Package rest imports 12 packages (graph) and is imported by 37 packages. Updated 2018-10-27. Refresh now. Tools for package owners.