httpclient

package module
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2023 License: MIT Imports: 6 Imported by: 0

README

Simple http client for go, easy to use

Example

result := Credential{}
client := httpclient.NewClient(
  	httpclient.WithSender(gosender.New(gosender.WithTimeout(time.Second * 5))),
)
statusCode, err := client.Post(context.Background(), "http://localhost:8080/login",
   	httpclient.WithBodyProvider(body.NewJson(Credential{
   		Username: "admin",
   		Password: "admin",
   	})),
   	httpclient.WithHookFn(hook.UnmarshalResponse(&result)),
   	httpclient.WithHookFn(hook.Log()),
)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chain

type Chain interface {
	Proceed(ctx context.Context, req *http.Request) (*http.Response, error)
	GetRequest(ctx context.Context) *http.Request
}

type Client

type Client interface {
	Get(ctx context.Context, url string, opts ...RequestOption) (int, error)
	Head(ctx context.Context, url string, opts ...RequestOption) (int, error)
	Post(ctx context.Context, url string, opts ...RequestOption) (int, error)
	Put(ctx context.Context, url string, opts ...RequestOption) (int, error)
	Patch(ctx context.Context, url string, opts ...RequestOption) (int, error)
	Delete(ctx context.Context, url string, opts ...RequestOption) (int, error)
	Connect(ctx context.Context, url string, opts ...RequestOption) (int, error)
	Options(ctx context.Context, url string, opts ...RequestOption) (int, error)
	Trace(ctx context.Context, url string, opts ...RequestOption) (int, error)
}

func NewClient

func NewClient(opts ...ClientOption) Client

type ClientOption

type ClientOption interface {
	// contains filtered or unexported methods
}

func WithClientHeader

func WithClientHeader(key, value string, isAdding ...bool) ClientOption

WithClientHeader sets the header entries associated with key to the single element value. It replaces any existing values associated with key. If isAdding[0] == true (default is false) then It appends to any existing values associated with key

func WithClientHookFn

func WithClientHookFn(hookFn HookFn) ClientOption

func WithSender

func WithSender(sender Sender) ClientOption

type HookFn

type HookFn func(ctx context.Context, reqChain Chain) (*http.Response, error)

type RequestHookFn

type RequestHookFn func(context.Context, *http.Request) error

type RequestOption

type RequestOption interface {
	// contains filtered or unexported methods
}

func WithBodyProvider

func WithBodyProvider(bProvider body.Provider) RequestOption

func WithHeader

func WithHeader(key, value string, isAdding ...bool) RequestOption

WithHeader sets the header entries associated with key to the single element value. It replaces any existing values associated with key. If isAdding[0] == true (default is false) then It appends to any existing values associated with key

func WithHookFn

func WithHookFn(hookFn HookFn) RequestOption

func WithQuery

func WithQuery(query interface{}) RequestOption

type ResponseHookFn

type ResponseHookFn func(context.Context, *http.Response) error

type Sender

type Sender interface {
	Send(ctx context.Context, req *http.Request) (*http.Response, error)
}

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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