rest

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 25, 2018 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultClient = &Client{HTTPClient: http.DefaultClient}

DefaultClient is used if no custom HTTP client is defined

Functions

func AddQueryParameters

func AddQueryParameters(baseURL string, queryParams map[string]string) string

AddQueryParameters adds query parameters to the URL.

func BuildRequestObject

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

BuildRequestObject creates the HTTP request object.

func MakeRequest

func MakeRequest(r *http.Request) (*http.Response, error)

MakeRequest makes the API call.

Types

type Client

type Client struct {
	HTTPClient *http.Client
}

Client allows modification of client headers, redirect policy and other settings See https://golang.org/pkg/net/http

func (*Client) API

func (c *Client) API(r *Request) (*Response, error)

API is the main interface to the API.

func (*Client) MakeRequest

func (c *Client) MakeRequest(req *http.Request) (*http.Response, error)

MakeRequest makes the API call.

type Method

type Method string

Method contains the supported HTTP verbs.

const (
	Get    Method = "GET"
	Post   Method = "POST"
	Put    Method = "PUT"
	Patch  Method = "PATCH"
	Delete Method = "DELETE"
)

Supported HTTP verbs.

type Request

type Request struct {
	Method      Method
	BaseURL     string // e.g. https://api.service.com
	Headers     map[string]string
	QueryParams map[string]string
	Body        []byte
}

Request holds the request to an API Call.

type Response

type Response struct {
	StatusCode int         // e.g. 200
	Headers    http.Header // e.g. map[X-Rate-Limit:[600]]
	Body       string      // e.g. {"result: success"}
	JSON       *gabs.Container
}

Response holds the response from an API call.

func API

func API(request *Request) (*Response, error)

API is the main interface to the API.

func BuildResponse

func BuildResponse(r *http.Response) (*Response, error)

BuildResponse builds the response struct.

func (*Response) ParseJSON

func (r *Response) ParseJSON() error

ParseJSON parses the response body to JSON container.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL