restclient2

package
v5.3.3 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HTTPClient

type HTTPClient struct {
	*http.Client
}

HTTPClient implements methods as a wrapper over the Go HttpClient

func (*HTTPClient) Do

func (h *HTTPClient) Do(req *http.Request) (*http.Response, error)

Do executes this HTTP request

func (*HTTPClient) SetTransport

func (h *HTTPClient) SetTransport(transport *http.Transport)

SetTransport sets the transport information for this HTTP client

type HTTPClientInterface

type HTTPClientInterface interface {
	Do(req *http.Request) (*http.Response, error)
	SetTransport(transport *http.Transport)
}

HTTPClientInterface is an interface over the Go HttpClient

type JSONClient

type JSONClient struct {
	BaseURL    string
	HTTPClient HTTPClientInterface
	// contains filtered or unexported fields
}

JSONClient provides a set of methods for working with RESTful endpoints that accept and return JSON data

func NewJSONClient

func NewJSONClient(baseURL string, httpClient HTTPClientInterface) JSONClient

NewJSONClient creates a new JSON-based REST client

func (JSONClient) DELETE

func (c JSONClient) DELETE(path string, successReceiver, errorReceiver interface{}) (bool, error)

DELETE performs an HTTP DELETE operation. You provide a path, which should exclude the the TLD, as this is defined in BaseURL. If your request requires authorization call WithAuthorization first, then DELETE.

Upon a 2xx response the successReceiver will be populated with the returned JSON data, and "true,nil" will be returned. If there is an error response from the server errorReceiver will be populated, and "false,nil" will be returned.

In the event that an error occured communicating with the server, or some other unforseen error occurs, "false,error" is returned.

func (JSONClient) GET

func (c JSONClient) GET(path string, successReceiver, errorReceiver interface{}) (bool, error)

GET performs an HTTP GET operation. You provide a path, which should exclude the the TLD, as this is defined in BaseURL. If your request requires authorization call WithAuthorization first, then GET.

Upon a 2xx response the successReceiver will be populated with the returned JSON data, and "true,nil" will be returned. If there is an error response from the server errorReceiver will be populated, and "false,nil" will be returned.

In the event that an error occured communicating with the server, or some other unforseen error occurs, "false,error" is returned.

func (JSONClient) POST

func (c JSONClient) POST(path string, body, successReceiver, errorReceiver interface{}) (bool, error)

POST performs an HTTP POST operation. You provide a path, which should exclude the the TLD, as this is defined in BaseURL. If your request requires authorization call WithAuthorization first, then POST.

Upon a 2xx response the successReceiver will be populated with the returned JSON data, and "true,nil" will be returned. If there is an error response from the server errorReceiver will be populated, and "false,nil" will be returned.

In the event that an error occured communicating with the server, or some other unforseen error occurs, "false,error" is returned.

func (JSONClient) PUT

func (c JSONClient) PUT(path string, body, successReceiver, errorReceiver interface{}) (bool, error)

PUT performs an HTTP PUT operation. You provide a path, which should exclude the the TLD, as this is defined in BaseURL. If your request requires authorization call WithAuthorization first, then PUT.

Upon a 2xx response the successReceiver will be populated with the returned JSON data, and "true,nil" will be returned. If there is an error response from the server errorReceiver will be populated, and "false,nil" will be returned.

In the event that an error occured communicating with the server, or some other unforseen error occurs, "false,error" is returned.

func (JSONClient) WithAuthorization

func (c JSONClient) WithAuthorization(auth string) RESTClient

WithAuthorization returns an instance of RESTClient with an authorization header set

type MockHTTPClient

type MockHTTPClient struct {
	DoFunc           func(req *http.Request) (*http.Response, error)
	SetTransportFunc func(transport *http.Transport)
}

MockHTTPClient is a mock HTTP client

func (*MockHTTPClient) Do

func (m *MockHTTPClient) Do(req *http.Request) (*http.Response, error)

Do mocks the HTTP Do method

func (*MockHTTPClient) SetTransport

func (m *MockHTTPClient) SetTransport(transport *http.Transport)

SetTransport mocks the SetTransport method

type MockRESTClient

type MockRESTClient struct {
	DELETEFunc            func(path string, successReceiver, errorReceiver interface{}) (bool, error)
	GETFunc               func(path string, successReceiver, errorReceiver interface{}) (bool, error)
	POSTFunc              func(path string, body, successReceiver, errorReceiver interface{}) (bool, error)
	PUTFunc               func(path string, body, successReceiver, errorReceiver interface{}) (bool, error)
	WithAuthorizationFunc func(auth string) RESTClient
}

MockRESTClient is a mock for RESTClient

func (MockRESTClient) DELETE

func (m MockRESTClient) DELETE(path string, successReceiver, errorReceiver interface{}) (bool, error)

DELETE is a mock method

func (MockRESTClient) GET

func (m MockRESTClient) GET(path string, successReceiver, errorReceiver interface{}) (bool, error)

GET is a mock method

func (MockRESTClient) POST

func (m MockRESTClient) POST(path string, body, successReceiver, errorReceiver interface{}) (bool, error)

POST is a mock method

func (MockRESTClient) PUT

func (m MockRESTClient) PUT(path string, body, successReceiver, errorReceiver interface{}) (bool, error)

PUT is a mock method

func (MockRESTClient) WithAuthorization

func (m MockRESTClient) WithAuthorization(auth string) RESTClient

WithAuthorization is a mock method

type RESTClient

type RESTClient interface {
	DELETE(path string, successReceiver, errorReceiver interface{}) (bool, error)
	GET(path string, successReceiver, errorReceiver interface{}) (bool, error)
	POST(path string, body, successReceiver, errorReceiver interface{}) (bool, error)
	PUT(path string, body, successReceiver, errorReceiver interface{}) (bool, error)
	WithAuthorization(auth string) RESTClient
}

RESTClient defines an interface for working with RESTful endpoints

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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