package builder
import "github.com/IBM/fp-go/http/builder"
Index ¶
- Variables
- func Header(name string) L.Lens[*Builder, O.Option[string]]
- func MakeHash(b *Builder) string
- func QueryArg(name string) L.Lens[*Builder, O.Option[string]]
- func WithHeader(name string) func(value string) Endomorphism
- func WithQueryArg(name string) func(value string) Endomorphism
- type Builder
- func (builder *Builder) DelHeader(name string) *Builder
- func (builder *Builder) GetBody() O.Option[E.Either[error, []byte]]
- func (builder *Builder) GetHash() string
- func (builder *Builder) GetHeader(name string) O.Option[string]
- func (builder *Builder) GetHeaderValues(name string) []string
- func (builder *Builder) GetHeaders() http.Header
- func (builder *Builder) GetMethod() string
- func (builder *Builder) GetQuery() url.Values
- func (builder *Builder) GetTargetURL() E.Either[error, string]
- func (builder *Builder) GetTargetUrl() E.Either[error, string]
- func (builder *Builder) GetURL() string
- func (builder *Builder) GetUrl() string
- func (builder *Builder) SetBody(body O.Option[E.Either[error, []byte]]) *Builder
- func (builder *Builder) SetHeader(name, value string) *Builder
- func (builder *Builder) SetHeaders(headers http.Header) *Builder
- func (builder *Builder) SetMethod(method string) *Builder
- func (builder *Builder) SetQuery(query url.Values) *Builder
- func (builder *Builder) SetURL(url string) *Builder
- func (builder *Builder) SetUrl(url string) *Builder
- type Endomorphism
Variables ¶
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 // // Deprecated: use [URL] instead Url = L.MakeLensRef((*Builder).GetURL, (*Builder).SetURL) // 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 the URL // // Deprecated: use [WithURL] instead WithUrl = URL.Set // WithURL creates a [Endomorphism] for the URL 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[E.Either[error, []byte]], Body.Set, ) // WithBytes creates a [Endomorphism] for a request body using bytes WithBytes = F.Flow2( E.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, ) // WithoutBody creates a [Endomorphism] to remove the body WithoutBody = F.Pipe1( noBody, Body.Set, ) // WithFormData creates a [Endomorphism] to send form data payload WithFormData = F.Flow4( url.Values.Encode, S.ToBytes, WithBytes, ENDO.Chain(WithContentType(C.FormEncoded)), ) )
Functions ¶
func Header ¶
Header returns a [L.Lens] for a single header
func MakeHash ¶
MakeHash converts a Builder into a hash string, convenient to use as a cache key
func QueryArg ¶
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 ¶
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) GetBody ¶
func (*Builder) GetHash ¶
GetHash returns a hash value for the builder that can be used as a cache key
func (*Builder) GetHeader ¶
func (*Builder) GetHeaderValues ¶
func (*Builder) GetHeaders ¶
func (*Builder) GetMethod ¶
func (*Builder) GetQuery ¶
func (*Builder) GetTargetURL ¶
GetTargetURL constructs a full URL with query parameters on top of the provided URL string
func (*Builder) GetTargetUrl ¶
GetTargetUrl constructs a full URL with query parameters on top of the provided URL string
Deprecated: use [GetTargetURL] instead
func (*Builder) GetURL ¶
func (*Builder) GetUrl ¶
Deprecated: use [GetURL] instead
func (*Builder) SetBody ¶
func (*Builder) SetHeader ¶
func (*Builder) SetHeaders ¶
func (*Builder) SetMethod ¶
func (*Builder) SetQuery ¶
func (*Builder) SetURL ¶
func (*Builder) SetUrl ¶
Deprecated: use [SetURL] instead
type Endomorphism ¶
type Endomorphism = ENDO.Endomorphism[*Builder]
Endomorphism returns an [ENDO.Endomorphism] that transforms a builder
func WithJSON ¶
func WithJSON[T any](data T) Endomorphism
WithJSON creates a Endomorphism to send JSON payload
func WithJson ¶
func WithJson[T any](data T) Endomorphism
WithJson creates a Endomorphism to send JSON payload
Deprecated: use WithJSON instead
func WithoutHeader ¶
func WithoutHeader(name string) Endomorphism
WithoutHeader creates a Endomorphism to remove a certain header
func WithoutQueryArg ¶
func WithoutQueryArg(name string) Endomorphism
WithoutQueryArg creates a Endomorphism that removes a query argument
Source Files ¶
- Version
- v1.0.151 (latest)
- Published
- Nov 23, 2024
- Platform
- linux/amd64
- Imports
- 20 packages
- Last checked
- 4 months ago –
Tools for package owners.