httpclient

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2025 License: MIT Imports: 9 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) MethodDelete

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

func (*Client) MethodGet

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

func (*Client) MethodPatch

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

func (*Client) MethodPost

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

func (*Client) MethodPut

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

type MultipartRequest added in v1.0.0

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

func (*MultipartRequest) Field added in v1.0.0

func (r *MultipartRequest) Field(name, value string) *MultipartRequest

func (*MultipartRequest) File added in v1.0.0

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

func (*MultipartRequest) GetMultipartRequest added in v1.0.1

func (r *MultipartRequest) GetMultipartRequest() (*MultipartRequest, error)

func (*MultipartRequest) Header added in v1.0.1

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

func (*MultipartRequest) Send added in v1.0.0

func (r *MultipartRequest) 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) JSONBody

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

func (*Request) Multipart

func (r *Request) Multipart() *MultipartRequest

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