api

package
v0.0.0-...-5623d4f Latest Latest
Warning

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

Go to latest
Published: May 12, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// Base is the base URL used for relative requests
	Base string

	// ValidateStatus is a function that validates the status code of the HTTP response
	ValidateStatus func(int) bool

	// Envelope is the name of the data field in the response
	Envelope string
}

func (Client) Do

func (c Client) Do(request *Request, v interface{}) (*Response, error)

Do performs the HTTP request. Relative URLs will have the base URL prepended. An error will be thrown if the response does not have a JSON content-type or if the status code is not valid. The entire response will be returned but the JSON will be unmarshalled into the second argument.

func (Client) Get

func (c Client) Get(url string, response interface{}) (*Response, error)

Get performs a GET request

func (Client) Patch

func (c Client) Patch(url string, body map[string]interface{}, response interface{}) (*Response, error)

Patch performs a PATCH request

func (Client) Put

func (c Client) Put(url string, body map[string]interface{}, response interface{}) (*Response, error)

Put performs a PUT request

type Request

type Request struct {
	Method string
	URL    string
	Body   map[string]interface{}
}

Request holds the information needed to make an HTTP request

type Requester

type Requester interface {
	Do(request *Request, resultData interface{}) (*Response, error)
	Get(url string, response interface{}) (*Response, error)
	Put(url string, body map[string]interface{}, response interface{}) (*Response, error)
	Patch(url string, body map[string]interface{}, response interface{}) (*Response, error)
}

Requester is an interface for making HTTP requests

var DefaultClient Requester

func New

func New(base string, envelope string) (Requester, error)

New returns a new API Client

type Response

type Response struct {
	*http.Response
	Body string
}

func Get

func Get(url string, response interface{}) (*Response, error)

func Patch

func Patch(url string, body map[string]interface{}, response interface{}) (*Response, error)

func Put

func Put(url string, body map[string]interface{}, response interface{}) (*Response, error)

Jump to

Keyboard shortcuts

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