jsonclient

package
Version: v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2021 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

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