restype

package module
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2023 License: MIT Imports: 4 Imported by: 0

README

restype

Convenient and strongly typed HTTP requests using resty client.

Documentation

Index

Constants

View Source
const (
	ErrorBodyFromRequest = iota
	ErrorExecuteRequest
	ErrorResponseFromBytes
)

Variables

This section is empty.

Functions

func Do

func Do[R Request[T], T any, E error](client *resty.Client, req R, opts ...RequestOptions) (t T, err error)

Do performs a request using resty.Client with request of type `Request[T]`, response of type `T`, error of type `error`.

Requests without response should specify the `any` type. Requests without typed error should specify the `error` type.

RequestOptions enable modification of the request.

func DoRaw added in v0.1.2

func DoRaw[R Request[T], T any, E error](client *resty.Client, req R, opts ...RequestOptions) (res *resty.Response, t T, err error)

DoRaw performs the same function as Do and returns the raw resty.Response.

Types

type Default

type Default struct{}

Default is a convenience struct for embedding that provides default (nil) implementation of optional Request[T] methods.

func (Default) Body

func (Default) Body() ([]byte, error)

func (Default) Headers

func (Default) Headers() map[string]string

func (Default) PathParams

func (Default) PathParams() map[string]string

func (Default) QueryParams

func (Default) QueryParams() map[string]string

func (Default) ResponseFromBytes

func (Default) ResponseFromBytes([]byte) (any, error)

type Error added in v0.1.5

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

func (Error) Error added in v0.1.5

func (e Error) Error() string

func (Error) Is added in v0.1.5

func (e Error) Is(target error) bool

func (Error) Unwrap added in v0.1.5

func (e Error) Unwrap() error

type ErrorKind added in v0.1.5

type ErrorKind int

func (ErrorKind) Error added in v0.1.5

func (e ErrorKind) Error() string

type Request

type Request[T any] interface {
	Method() string
	Path() string
	PathParams() map[string]string
	QueryParams() map[string]string
	Headers() map[string]string
	Body() ([]byte, error)
	ResponseFromBytes([]byte) (T, error)
}

Request[T] represents a request with a response of type T.

type RequestOptions added in v0.1.4

type RequestOptions func(*resty.Request) *resty.Request

RequestOptions are functions that modify resty.Request and return a reference to it.

Allows for modifying the request where required or where it does not make sense to add to implementations of Request[T].

Jump to

Keyboard shortcuts

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