httpclient

package module
v0.0.0-...-1347aec Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2025 License: MIT Imports: 10 Imported by: 0

README

Go Reference Report card

httpclient

Simple valyala/fasthttp wrapper library with user-friendly interface and built-in request/response acquire and release.

Installation

go get github.com/Cleverse/go-utilities/httpclient

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

func New

func New(baseURL string, config ...Config) (*Client, error)

func NewFromClient

func NewFromClient(client *fasthttp.Client, baseURL string, config ...Config) (*Client, error)

func (*Client) BaseURL

func (h *Client) BaseURL() *url.URL

BaseURL returns the cloned base URL of the client.

func (*Client) Delete

func (h *Client) Delete(ctx context.Context, path string, reqOptions RequestOptions) (*HttpResponse, error)

func (*Client) Do

func (h *Client) Do(ctx context.Context, method, path string, reqOptions RequestOptions) (*HttpResponse, error)

func (*Client) Get

func (h *Client) Get(ctx context.Context, path string, reqOptions RequestOptions) (*HttpResponse, error)

func (*Client) Patch

func (h *Client) Patch(ctx context.Context, path string, reqOptions RequestOptions) (*HttpResponse, error)

func (*Client) Post

func (h *Client) Post(ctx context.Context, path string, reqOptions RequestOptions) (*HttpResponse, error)

func (*Client) Put

func (h *Client) Put(ctx context.Context, path string, reqOptions RequestOptions) (*HttpResponse, error)

type Config

type Config struct {
	// Enable debug mode
	Debug bool

	// Default headers
	Headers map[string]string
}

type HttpResponse

type HttpResponse struct {
	URL string
	fasthttp.Response
}

func Delete

func Delete(ctx context.Context, path string, reqOptions RequestOptions) (*HttpResponse, error)

Delete is a shortcut for New(path).Delete(ctx, path, reqOptions)

func Do

func Do(ctx context.Context, method, path string, reqOptions RequestOptions) (*HttpResponse, error)

Do is a shortcut for New(path).Do(ctx, method, "", reqOptions)

func Get

func Get(ctx context.Context, path string, reqOptions RequestOptions) (*HttpResponse, error)

Get is a shortcut for New(path).Get(ctx, path, reqOptions)

func Patch

func Patch(ctx context.Context, path string, reqOptions RequestOptions) (*HttpResponse, error)

Patch is a shortcut for New(path).Patch(ctx, path, reqOptions)

func Post

func Post(ctx context.Context, path string, reqOptions RequestOptions) (*HttpResponse, error)

Post is a shortcut for New(path).Post(ctx, path, reqOptions)

func Put

func Put(ctx context.Context, path string, reqOptions RequestOptions) (*HttpResponse, error)

Put is a shortcut for New(path).Put(ctx, path, reqOptions)

func (*HttpResponse) UnmarshalBody

func (r *HttpResponse) UnmarshalBody(out any) error

type RequestOptions

type RequestOptions struct {
	Body     []byte
	Query    url.Values
	Header   map[string]string
	FormData url.Values
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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