builder

package
v1.0.93 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Default is the default builder
	Default = &Builder{method: O.Some(defaultMethod()), headers: make(http.Header), body: noBody}

	// Monoid is the [M.Monoid] for the [Endomorphism]
	Monoid = ENDO.Monoid[*Builder]()

	// Url is a [L.Lens] for the URL
	Url = L.MakeLensRef((*Builder).GetUrl, (*Builder).SetUrl)
	// Method is a [L.Lens] for the HTTP method
	Method = L.MakeLensRef((*Builder).GetMethod, (*Builder).SetMethod)
	// Body is a [L.Lens] for the request body
	Body = L.MakeLensRef((*Builder).GetBody, (*Builder).SetBody)
	// Headers is a [L.Lens] for the complete set of request headers
	Headers = L.MakeLensRef((*Builder).GetHeaders, (*Builder).SetHeaders)
	// Query is a [L.Lens] for the set of query parameters
	Query = L.MakeLensRef((*Builder).GetQuery, (*Builder).SetQuery)

	// WithQuery creates a [Endomorphism] for a complete set of query parameters
	WithQuery = Query.Set
	// WithMethod creates a [Endomorphism] for a certain method
	WithMethod = Method.Set
	// WithUrl creates a [Endomorphism] for a certain method
	WithUrl = Url.Set
	// WithHeaders creates a [Endomorphism] for a set of headers
	WithHeaders = Headers.Set
	// WithBody creates a [Endomorphism] for a request body
	WithBody = F.Flow2(
		O.Of[IOE.IOEither[error, []byte]],
		Body.Set,
	)
	// WithBytes creates a [Endomorphism] for a request body using bytes
	WithBytes = F.Flow2(
		IOE.Of[error, []byte],
		WithBody,
	)
	// WithContentType adds the [H.ContentType] header
	WithContentType = WithHeader(H.ContentType)
	// WithAuthorization adds the [H.Authorization] header
	WithAuthorization = WithHeader(H.Authorization)

	// WithGet adds the [http.MethodGet] method
	WithGet = WithMethod(http.MethodGet)
	// WithPost adds the [http.MethodPost] method
	WithPost = WithMethod(http.MethodPost)
	// WithPut adds the [http.MethodPut] method
	WithPut = WithMethod(http.MethodPut)
	// WithDelete adds the [http.MethodDelete] method
	WithDelete = WithMethod(http.MethodDelete)

	// WithBearer creates a [Endomorphism] to add a Bearer [H.Authorization] header
	WithBearer = F.Flow2(
		S.Format[string]("Bearer %s"),
		WithAuthorization,
	)

	// Requester creates a requester from a builder
	Requester = (*Builder).Requester

	// WithoutBody creates a [Endomorphism] to remove the body
	WithoutBody = F.Pipe1(
		noBody,
		Body.Set,
	)
)

Functions

func Header(name string) L.Lens[*Builder, O.Option[string]]

Header returns a [L.Lens] for a single header

func QueryArg added in v1.0.93

func QueryArg(name string) L.Lens[*Builder, O.Option[string]]

QueryArg is a [L.Lens] for the first value of a query argument

func WithHeader

func WithHeader(name string) func(value string) Endomorphism

WithHeader creates a Endomorphism for a certain header

func WithQueryArg added in v1.0.93

func WithQueryArg(name string) func(value string) Endomorphism

WithQueryArg creates a Endomorphism for a certain query argument

Types

type Builder

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

func (*Builder) DelHeader

func (builder *Builder) DelHeader(name string) *Builder

func (*Builder) GetBody

func (builder *Builder) GetBody() O.Option[IOE.IOEither[error, []byte]]

func (*Builder) GetHeader

func (builder *Builder) GetHeader(name string) O.Option[string]

func (*Builder) GetHeaderValues

func (builder *Builder) GetHeaderValues(name string) []string

func (*Builder) GetHeaders

func (builder *Builder) GetHeaders() http.Header

func (*Builder) GetMethod

func (builder *Builder) GetMethod() string

func (*Builder) GetQuery added in v1.0.93

func (builder *Builder) GetQuery() url.Values

func (*Builder) GetUrl

func (builder *Builder) GetUrl() string

func (*Builder) Requester

func (builder *Builder) Requester() IOEH.Requester

func (*Builder) SetBody

func (builder *Builder) SetBody(body O.Option[IOE.IOEither[error, []byte]]) *Builder

func (*Builder) SetHeader

func (builder *Builder) SetHeader(name, value string) *Builder

func (*Builder) SetHeaders

func (builder *Builder) SetHeaders(headers http.Header) *Builder

func (*Builder) SetMethod

func (builder *Builder) SetMethod(method string) *Builder

func (*Builder) SetQuery added in v1.0.93

func (builder *Builder) SetQuery(query url.Values) *Builder

func (*Builder) SetUrl

func (builder *Builder) SetUrl(url string) *Builder

type Endomorphism added in v1.0.77

type Endomorphism = ENDO.Endomorphism[*Builder]

Endomorphism returns an [ENDO.Endomorphism] that transforms a builder

func WithFormData added in v1.0.72

func WithFormData(value url.Values) Endomorphism

WithFormData creates a Endomorphism to send form data payload

func WithJson added in v1.0.72

func WithJson[T any](data T) Endomorphism

WithJson creates a Endomorphism to send JSON payload

func WithoutHeader

func WithoutHeader(name string) Endomorphism

WithoutHeader creates a Endomorphism to remove a certain header

func WithoutQueryArg added in v1.0.93

func WithoutQueryArg(name string) Endomorphism

WithoutQueryArg creates a Endomorphism that removes a query argument

Jump to

Keyboard shortcuts

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