rest

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package rest provides convenience and sensible defaults for some low level http client

Index

Constants

This section is empty.

Variables

View Source
var TimeoutError = errors.New("client request timeout")

Functions

func NewHTTPError

func NewHTTPError(code int, msg string) error

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func Create

func Create(config configs.HTTPClientConfig) *Client

func (Client) GetJSON

func (c Client) GetJSON(ctx context.Context, req *HTTPRequest, resp any) error

GetJson Issue GET request with expected json response

func (Client) GetXML

func (c Client) GetXML(ctx context.Context, req *HTTPRequest, resp any) error

GetXML Issue GET request with expected XML response

func (Client) PostJSON

func (c Client) PostJSON(ctx context.Context, req *HTTPRequest, resp any) error

PostJson Issue POST request with expected json response

func (Client) PostXML

func (c Client) PostXML(ctx context.Context, req HTTPRequest, resp any) error

PostXML Issue POST request with expected XML response

func (Client) PutJSON

func (c Client) PutJSON(ctx context.Context, req *HTTPRequest, resp any) error

PutJson Issue PUT request with expected json response

func (Client) PutXML

func (c Client) PutXML(ctx context.Context, req *HTTPRequest, resp any) error

PutXML Issue PUT request with expected XML response

type HTTPClientJSONInterface

type HTTPClientJSONInterface interface {
	GetJSON(ctx context.Context, req *HTTPRequest, resp any) error
	PostJSON(ctx context.Context, req *HTTPRequest, resp any) error
	PutJSON(ctx context.Context, req *HTTPRequest, resp any) error
}

HTTPClientJSONInterface interface for client with JSON responses

type HTTPClientXMLInterface

type HTTPClientXMLInterface interface {
	GetXML(ctx context.Context, req *HTTPRequest, resp any) error
	PutXML(ctx context.Context, req *HTTPRequest, resp any) error
	PostXML(ctx context.Context, req *HTTPRequest, resp any) error
}

HTTPClientXMLInterface interface for client with XML responses

type HTTPError

type HTTPError struct {
	Message string
	Code    int
}

HTTPError error returned from Client

func (HTTPError) Error

func (e HTTPError) Error() string

type HTTPRequest

type HTTPRequest struct {
	Body    any
	Headers map[string]string
	Query   map[string]string
	URL     string
}

HTTPRequest represents a http request

Jump to

Keyboard shortcuts

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