httpx

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultTimeout = 10 * time.Second
)

Variables

View Source
var BodyParsers = map[string]BodyParser{
	"text/plain":       TextBodyParser,
	"application/json": JsonBodyParser,
}
View Source
var DefaultClient = NewClient()

Functions

func JsonBodyParser

func JsonBodyParser(buf io.Reader, bodyPtr any) (err error)

JsonBodyParser parses application/json content type

func TextBodyParser

func TextBodyParser(buf io.Reader, bodyPtr any) (err error)

TextBodyParser parses text/plain content type

Types

type BodyParser

type BodyParser func(buf io.Reader, bodyPtr any) (err error)

type Client

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

func NewClient

func NewClient(options ...ClientOption) *Client

func (*Client) Delete

func (c *Client) Delete(url string, options ...ReqOption) (res *Response, err error)

func (*Client) Do

func (c *Client) Do(method string, url *url.URL, options ...ReqOption) (res *Response, err error)

Do makes a request to the url with given options res should be Closed after use

func (*Client) Get

func (c *Client) Get(url string, options ...ReqOption) (res *Response, err error)

func (*Client) Head

func (c *Client) Head(url string, options ...ReqOption) (res *Response, err error)

func (*Client) Options

func (c *Client) Options(url string, options ...ReqOption) (res *Response, err error)

func (*Client) Post

func (c *Client) Post(url string, options ...ReqOption) (res *Response, err error)

func (*Client) Put

func (c *Client) Put(url string, options ...ReqOption) (res *Response, err error)

type ClientOption

type ClientOption func(clientOptions *clientOptions)

func WithDefaultBodyParser added in v0.4.0

func WithDefaultBodyParser(contentType string, parser BodyParser) ClientOption

func WithDefaultHeaders added in v0.2.0

func WithDefaultHeaders(headers map[string][]string) ClientOption

func WithTimeout

func WithTimeout(timeout time.Duration) ClientOption

type Marshaller added in v0.4.0

type Marshaller func(objPtr any) ([]byte, error)

type ReqOption

type ReqOption func(req *Request) error

func WithBodyParser added in v0.3.0

func WithBodyParser(contentType string, bodyParser BodyParser) ReqOption

WithBodyParser sets ResponseBodyParser

func WithBuffer

func WithBuffer(contentType string, body *bytes.Buffer) ReqOption

func WithBytes

func WithBytes(contentType string, body []byte) ReqOption

func WithFormData

func WithFormData(fields map[string]string) ReqOption

func WithHeader

func WithHeader(key, value string) ReqOption

func WithHeaders

func WithHeaders(headers map[string]string) ReqOption

func WithJsonObject

func WithJsonObject(obj any) ReqOption

func WithJsonString

func WithJsonString(json string) ReqOption

func WithMarshalObject added in v0.4.0

func WithMarshalObject(contentType string, obj any, marshaller Marshaller) ReqOption

func WithMultipartFile

func WithMultipartFile(fieldName string, file *os.File) ReqOption

func WithMultipartReader

func WithMultipartReader(fieldName string, filename string, reader io.Reader) ReqOption

func WithPath

func WithPath(path string) ReqOption

func WithQueries

func WithQueries(queries map[string][]string) ReqOption

func WithQuery

func WithQuery(key, value string) ReqOption

func WithString

func WithString(contentType string, body string) ReqOption

type Request

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

type Response

type Response struct {
	io.Closer
	// contains filtered or unexported fields
}

func (*Response) BufferedReader

func (c *Response) BufferedReader() *bufio.Reader

BufferedReader returns the reader for body [Close] will close the body

func (*Response) Close

func (c *Response) Close()

Closer interface

func (*Response) Header

func (c *Response) Header() map[string][]string

func (*Response) Status

func (c *Response) Status() string

func (*Response) StatusCode

func (c *Response) StatusCode() int

func (*Response) Unmarshal

func (c *Response) Unmarshal(ptrType any) (err error)

Unmarshal unmarshal body and close the body stream

Jump to

Keyboard shortcuts

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