request

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

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

HTTP header constants used throughout the request package.

Variables

This section is empty.

Functions

This section is empty.

Types

type Multipart

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

Multipart represents a multipart/form-data request builder. It uses streaming with io.Pipe to avoid buffering the entire request in memory.

func NewMultipart

func NewMultipart(ctx context.Context, c *http.Client, method, url string) *Multipart

NewMultipart creates a new multipart/form-data request builder. If the request creation fails, the error will be returned when Send is called.

func NewMultipartWithOpsCapacity added in v1.4.1

func NewMultipartWithOpsCapacity(ctx context.Context, c *http.Client, method, url string, opsCapacity int) *Multipart

func (*Multipart) Bool

func (r *Multipart) Bool(fieldName string, value bool) *Multipart

Bool adds a boolean form field to the multipart request.

func (*Multipart) File

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

File adds a file field to the multipart request. The content will be read when Send is called.

func (*Multipart) Float

func (r *Multipart) Float(fieldName string, value float64) *Multipart

Float adds a float64 form field to the multipart request.

func (*Multipart) Header

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

Header adds a header to the request. This is applied immediately, not deferred.

func (*Multipart) Param

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

Param adds a form field to the multipart request.

func (*Multipart) Send

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

Send executes all deferred operations in a goroutine and sends the multipart request. The multipart data is streamed using io.Pipe to avoid memory buffering.

type Request

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

Request represents an HTTP request builder that uses deferred operations. All configuration methods are applied only when Send is called.

func NewRequest

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

NewRequest creates a new HTTP request builder. If the request creation fails, the error will be returned when Send is called.

func NewRequestWithOpsCapacity added in v1.4.1

func NewRequestWithOpsCapacity(ctx context.Context, c *http.Client, method, url string, opsCapacity int) *Request

func (*Request) Body

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

Body sets the request body. Any existing body will be closed when Send is called.

func (*Request) Bool

func (r *Request) Bool(fieldName string, value bool) *Request

Bool adds a boolean URL query parameter to the request.

func (*Request) Bytes

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

Bytes sets the request body from a byte slice and sets the Content-Length header.

func (*Request) Float

func (r *Request) Float(fieldName string, value float64) *Request

Float adds a float64 URL query parameter to the request.

func (*Request) Header

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

Header adds a header to the request. The header is set when Send is called.

func (*Request) JSON

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

JSON marshals the provided value to JSON and sets it as the request body. Also sets the Content-Type header to application/json.

func (*Request) Param

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

Param adds a URL query parameter to the request.

func (*Request) Send

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

Send executes all deferred operations and sends the HTTP request. Returns the HTTP response or the first error encountered.

Jump to

Keyboard shortcuts

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