httpz

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DoJSON

func DoJSON[R any](c *http.Client, req *http.Request) (res *R, err error)

DoJSON performs the request and unmarshals the response body into a new R.

func JSON

func JSON[R any](ctx context.Context, c *http.Client, method, url string, data any,
) (res *R, err error)

JSON performs the request with the data marshaled to JSON format and unmarshals the response body into a new R.

func NewJSONRequest

func NewJSONRequest(ctx context.Context, method, url string, data any,
) (res *http.Request, err error)

NewJSONRequest returns a new http.Request with the given data marshaled to JSON format.

func RawJSON added in v0.3.0

func RawJSON(ctx context.Context, c *http.Client, method, url string, data any,
) (res *http.Response, err error)

RawJSON performs the request with the data marshaled to JSON format and returns the raw response.

func RespJSON

func RespJSON[R any](r *http.Response) (res *R, err error)

RespJSON unmarshals the response body into a new R and closes the body afterwards.

Types

type ErrorResp added in v0.3.0

type ErrorResp[T any] struct {
	*http.Response
	T *T
}

ErrorResp is the error response.

func DoJSON2 added in v0.3.0

func DoJSON2[R, E any](c *http.Client, req *http.Request) (res *R, er ErrorResp[E], err error)

DoJSON2 likes the DoJSON, but can specify the error response type.

func JSON2 added in v0.3.0

func JSON2[R, E any](ctx context.Context, c *http.Client, method, url string, data any,
) (res *R, er ErrorResp[E], err error)

JSON2 likes the JSON, but can specify the error response type.

func (ErrorResp[T]) IsZero added in v0.3.0

func (er ErrorResp[T]) IsZero() bool

IsZero reports whether the ErrorResp is zero.

Jump to

Keyboard shortcuts

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