rest: github.com/sendgrid/rest Index | Files | Directories

package rest

import "github.com/sendgrid/rest"

Package rest allows for quick and easy access any REST or REST-like API.

Index

Package Files

rest.go

Variables

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

DefaultClient is used if no custom HTTP client is defined

func AddQueryParameters Uses

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

AddQueryParameters adds query parameters to the URL.

func BuildRequestObject Uses

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

BuildRequestObject creates the HTTP request object.

func MakeRequest Uses

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

MakeRequest makes the API call.

type Client Uses

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 Uses

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

Deprecated: API supports old implementation

func (*Client) MakeRequest Uses

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

MakeRequest makes the API call.

func (*Client) Send Uses

func (c *Client) Send(request Request) (*Response, error)

Send will build your request, make the request, and build your response.

type Method Uses

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 Uses

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

Request holds the request to an API Call.

type Response Uses

type Response struct {
    StatusCode int                 // e.g. 200
    Body       string              // e.g. {"result: success"}
    Headers    map[string][]string // e.g. map[X-Ratelimit-Limit:[600]]
}

Response holds the response from an API call.

func API Uses

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

Deprecated: API supports old implementation

func BuildResponse Uses

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

BuildResponse builds the response struct.

func Send Uses

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

Send uses the DefaultClient to send your request

type RestError Uses

type RestError struct {
    Response *Response
}

RestError is a struct for an error handling.

func (*RestError) Error Uses

func (e *RestError) Error() string

Error is the implementation of the error interface.

Directories

PathSynopsis
examples

Package rest imports 4 packages (graph) and is imported by 20 packages. Updated 2018-11-03. Refresh now. Tools for package owners.