httpclient

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2025 License: MIT Imports: 10 Imported by: 1

README

HTTP Client

Universal HTTP client with method chaining for building requests.

Features

  • Method chaining
  • Multipart/form-data support
  • Header management
  • Thread-safe operations
  • Buffer pooling

Usage

client, err := httpclient.NewClient(&http.Client{}, "https://api.example.com")
if err != nil {
    panic(err)
}

resp, err := client.MethodPost(context.Background(), "/endpoint").
    Header("Authorization", "Bearer token").
    JSONBody(map[string]string{"key": "value"}).
    Send()

API

Client:

  • NewClient(httpClient *http.Client, baseURL string) (*Client, error)
  • MethodGet/Post/Put/Patch/Delete(ctx context.Context, path string) *Request

Request:

  • Header(key, value string) *Request
  • QueryParam(key, value string) *Request
  • JSONBody(body any) *Request
  • File(fieldName, filename string, content io.Reader) *Request
  • FormField(fieldName, value string) *Request
  • Send() (*http.Response, error)

Documentation

Index

Constants

View Source
const (
	ApplicationJSON = "application/json"
	ContentType     = "Content-Type"
	ContentLength   = "Content-Length"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient(client *http.Client, baseURL string) (*Client, error)

func (*Client) MultipartPOST added in v1.2.0

func (c *Client) MultipartPOST(ctx context.Context, path string) *Multipart

func (*Client) NewMultipartRequest added in v1.2.0

func (c *Client) NewMultipartRequest(ctx context.Context, method, path string) *Multipart

func (*Client) NewRequest added in v1.2.0

func (c *Client) NewRequest(ctx context.Context, method, path string) *Request

func (*Client) RequestDELETE added in v1.2.0

func (c *Client) RequestDELETE(ctx context.Context, path string) *Request

func (*Client) RequestGET added in v1.2.0

func (c *Client) RequestGET(ctx context.Context, path string) *Request

func (*Client) RequestPATCH added in v1.2.0

func (c *Client) RequestPATCH(ctx context.Context, path string) *Request

func (*Client) RequestPOST added in v1.2.0

func (c *Client) RequestPOST(ctx context.Context, path string) *Request

func (*Client) RequestPUT added in v1.2.0

func (c *Client) RequestPUT(ctx context.Context, path string) *Request

type Multipart added in v1.1.0

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

func (*Multipart) ContentType added in v1.1.0

func (r *Multipart) ContentType(contentType string) *Multipart

func (*Multipart) File added in v1.1.0

func (r *Multipart) File(fieldName, filename string, content io.Reader) *Multipart

func (*Multipart) FormField added in v1.1.0

func (r *Multipart) FormField(fieldName, value string) *Multipart

func (*Multipart) GetRequest added in v1.1.0

func (r *Multipart) GetRequest() (*Multipart, error)

func (*Multipart) Header added in v1.1.0

func (r *Multipart) Header(key, value string) *Multipart

func (*Multipart) Headers added in v1.1.0

func (r *Multipart) Headers(headers map[string]string) *Multipart

func (*Multipart) Send added in v1.1.0

func (r *Multipart) Send() (*http.Response, error)

type Request

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

func (*Request) Body

func (r *Request) Body(body io.ReadCloser) *Request

func (*Request) BytesBody

func (r *Request) BytesBody(body []byte) *Request

func (*Request) ContentType

func (r *Request) ContentType(contentType string) *Request

func (*Request) GetRequest added in v0.0.4

func (r *Request) GetRequest() (*Request, error)

func (*Request) Header

func (r *Request) Header(key, value string) *Request

func (*Request) Headers

func (r *Request) Headers(headers map[string]string) *Request

func (*Request) JSONBody

func (r *Request) JSONBody(body any) *Request

func (*Request) QueryParam

func (r *Request) QueryParam(key, value string) *Request

func (*Request) QueryParams

func (r *Request) QueryParams(params map[string]string) *Request

func (*Request) QueryValues

func (r *Request) QueryValues(values url.Values) *Request

func (*Request) Send

func (r *Request) Send() (*http.Response, error)

func (*Request) StringBody

func (r *Request) StringBody(body string) *Request

Jump to

Keyboard shortcuts

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