jsonclient

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const ContentType = "application/json"

ContentType is the default mime type for JSON

Variables

View Source
var DefaultClient = NewClient()

DefaultClient is the singleton instance of jsonclient using http.DefaultClient

Functions

func ErrorBody

func ErrorBody(e error) string

ErrorBody returns the request body from an Error

func Get

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

Get fetches url using GET and unmarshals into the passed response using DefaultClient

func Post

func Post(url string, request interface{}, response interface{}) error

Post sends request as JSON and unmarshals the response JSON into the supplied struct using DefaultClient

Types

type Client

type Client interface {
	Get(url string, response interface{}) error
	Post(url string, request interface{}, response interface{}) error
	Headers() http.Header
	ErrorResponse(err error, response interface{}) bool
}

func NewClient

func NewClient() Client

NewClient returns a new JSON Client using the default http.Client

func NewWithHTTPClient added in v0.6.0

func NewWithHTTPClient(httpClient *http.Client) Client

NewWithHTTPClient returns a new JSON Client using the specified http.Client

type Error

type Error struct {
	StatusCode int
	Body       string
	// contains filtered or unexported fields
}

Error contains additional http/JSON details

func (Error) Error

func (je Error) Error() string

func (Error) String

func (je Error) String() string

Jump to

Keyboard shortcuts

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