Documentation ¶
Overview ¶
Package httpf provides HTTP request utilities similar to github.com/carlmjohnson/requests but with support of github.com/carlmjohnson/flu IO capabilities.
Index ¶
- func NewDefaultTransport() *http.Transport
- type Authorization
- type Catch
- type CatchFunc
- type Client
- type ContentType
- type ContentTypeError
- type ExchangeResult
- func (r *ExchangeResult) Catch(catch Catch) *ExchangeResult
- func (r *ExchangeResult) CatchFunc(catch CatchFunc) *ExchangeResult
- func (r *ExchangeResult) CheckContentType(value string) *ExchangeResult
- func (r *ExchangeResult) CheckStatus(codes ...int) *ExchangeResult
- func (r *ExchangeResult) CopyBody(out flu.Output) *ExchangeResult
- func (r *ExchangeResult) DecodeBody(decoder flu.DecoderFrom) *ExchangeResult
- func (r *ExchangeResult) Error() error
- func (r *ExchangeResult) Handle(handler ResponseHandler) *ExchangeResult
- func (r *ExchangeResult) HandleFunc(handler ResponseHandlerFunc) *ExchangeResult
- func (r *ExchangeResult) Reader() (io.Reader, error)
- type Form
- type MultipartForm
- type RequestBuilder
- func CONNECT(resource string) *RequestBuilder
- func DELETE(resource string) *RequestBuilder
- func GET(resource string) *RequestBuilder
- func HEAD(resource string) *RequestBuilder
- func OPTIONS(resource string) *RequestBuilder
- func PATCH(resource string) *RequestBuilder
- func POST(resource string, body flu.EncoderTo) *RequestBuilder
- func PUT(resource string) *RequestBuilder
- func Request(resource string) *RequestBuilder
- func TRACE(resource string) *RequestBuilder
- func (r *RequestBuilder) Auth(auth Authorization) *RequestBuilder
- func (r *RequestBuilder) Body(encoder flu.EncoderTo) *RequestBuilder
- func (r *RequestBuilder) BodyInput(input flu.Input) *RequestBuilder
- func (r *RequestBuilder) ContentLength(contentLength int64) *RequestBuilder
- func (r *RequestBuilder) ContentType(contentType string) *RequestBuilder
- func (r *RequestBuilder) Exchange(ctx context.Context, client Client) *ExchangeResult
- func (r *RequestBuilder) Header(key, value string) *RequestBuilder
- func (r *RequestBuilder) Headers(kvPairs ...string) *RequestBuilder
- func (r *RequestBuilder) Method(value string) *RequestBuilder
- func (r *RequestBuilder) Query(key, value string) *RequestBuilder
- func (r *RequestBuilder) QueryValues(values url.Values) *RequestBuilder
- func (r RequestBuilder) String() string
- type ResponseHandler
- type ResponseHandlerFunc
- type RoundTripperFunc
- type StatusCodeError
- type VarargsLengthError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewDefaultTransport ¶ added in v0.10.5
NewDefaultTransport creates a new http.Transport based on http.DefaultTransport.
Types ¶
type Authorization ¶
Authorization is used to set Authorization headers in requests.
func Basic ¶
func Basic(username, password string) Authorization
Basic returns Basic Authorization header.
type ContentType ¶
type ContentType interface {
ContentType() string
}
ContentType is an interface which may be optionally implemented by flu.EncoderTo implementations to automatically set Content-Type header in requests.
type ContentTypeError ¶
type ContentTypeError string
ContentTypeError is returned when response Content-Type does not match the expected one.
func (ContentTypeError) Error ¶
func (e ContentTypeError) Error() string
type ExchangeResult ¶ added in v0.10.5
ExchangeResult is a fluent response wrapper.
func ExchangeError ¶ added in v0.10.5
func ExchangeError(err error) *ExchangeResult
ExchangeError returns an ExchangeResult stub with error set.
func (*ExchangeResult) Catch ¶ added in v0.10.5
func (r *ExchangeResult) Catch(catch Catch) *ExchangeResult
Catch processes and overwrites the error if it occurred.
func (*ExchangeResult) CatchFunc ¶ added in v0.10.5
func (r *ExchangeResult) CatchFunc(catch CatchFunc) *ExchangeResult
CatchFunc is like Catch, but accepts functions.
func (*ExchangeResult) CheckContentType ¶ added in v0.10.5
func (r *ExchangeResult) CheckContentType(value string) *ExchangeResult
CheckContentType checks the response Content-Type and returns error if it does not match the value. It closes response body on failure.
func (*ExchangeResult) CheckStatus ¶ added in v0.10.5
func (r *ExchangeResult) CheckStatus(codes ...int) *ExchangeResult
CheckStatus checks the response status code and sets the error to StatusCodeError if there is no match. It closes response body on failure.
func (*ExchangeResult) CopyBody ¶ added in v0.11.0
func (r *ExchangeResult) CopyBody(out flu.Output) *ExchangeResult
CopyBody copies response body to flu.Output.
func (*ExchangeResult) DecodeBody ¶ added in v0.10.5
func (r *ExchangeResult) DecodeBody(decoder flu.DecoderFrom) *ExchangeResult
DecodeBody decodes response body using the provided decoder.
func (*ExchangeResult) Error ¶ added in v0.10.5
func (r *ExchangeResult) Error() error
Error terminates the exchange, closes response body if necessary, and returns an error if any.
func (*ExchangeResult) Handle ¶ added in v0.10.5
func (r *ExchangeResult) Handle(handler ResponseHandler) *ExchangeResult
Handle executes a ResponseHandler if no previous handling errors occurred.
func (*ExchangeResult) HandleFunc ¶ added in v0.10.5
func (r *ExchangeResult) HandleFunc(handler ResponseHandlerFunc) *ExchangeResult
HandleFunc is like Handle, but accepts functions.
type Form ¶
type Form struct {
// contains filtered or unexported fields
}
Form represents a HTTP form request body.
func FormValue ¶ added in v0.10.5
func FormValue(value interface{}) *Form
FormValue creates a Form based on this value. It uses `url` tags for property name resolution.
func (*Form) ContentType ¶
func (*Form) Multipart ¶
func (f *Form) Multipart() *MultipartForm
Multipart creates a MultipartForm using this Form as property base.
type MultipartForm ¶
type MultipartForm struct { // Form contains form values (except for files). Form // contains filtered or unexported fields }
MultipartForm represents a multipart/form-data request body.
func (*MultipartForm) ContentType ¶
func (mf *MultipartForm) ContentType() string
func (*MultipartForm) File ¶
func (mf *MultipartForm) File(fieldName, filename string, input flu.Input) *MultipartForm
File adds a file to the form data.
func (*MultipartForm) Set ¶
func (mf *MultipartForm) Set(key string, values ...string) *MultipartForm
Set sets form values.
type RequestBuilder ¶ added in v0.10.5
RequestBuilder provides methods for building a http.Request.
func CONNECT ¶ added in v0.10.5
func CONNECT(resource string) *RequestBuilder
CONNECT creates a CONNECT HTTP request.
func DELETE ¶ added in v0.10.5
func DELETE(resource string) *RequestBuilder
DELETE creates a DELETE HTTP request.
func HEAD ¶ added in v0.10.5
func HEAD(resource string) *RequestBuilder
HEAD creates a HEAD HTTP request.
func OPTIONS ¶ added in v0.10.5
func OPTIONS(resource string) *RequestBuilder
OPTIONS creates an OPTIONS HTTP request.
func PATCH ¶ added in v0.10.5
func PATCH(resource string) *RequestBuilder
PATCH creates a PATCH HTTP request.
func POST ¶
func POST(resource string, body flu.EncoderTo) *RequestBuilder
POST creates a POST HTTP request.
func PUT ¶ added in v0.10.5
func PUT(resource string) *RequestBuilder
PUT creates a PUT HTTP request.
func TRACE ¶ added in v0.10.5
func TRACE(resource string) *RequestBuilder
TRACE creates a TRACE HTTP request.
func (*RequestBuilder) Auth ¶ added in v0.10.5
func (r *RequestBuilder) Auth(auth Authorization) *RequestBuilder
func (*RequestBuilder) Body ¶ added in v0.10.5
func (r *RequestBuilder) Body(encoder flu.EncoderTo) *RequestBuilder
Body is used to specify the request body as flu.EncoderTo. Note that if passed encoder implements ContentType interface, it will be used to set Content-Type header automatically.
func (*RequestBuilder) BodyInput ¶ added in v0.10.5
func (r *RequestBuilder) BodyInput(input flu.Input) *RequestBuilder
BodyInput is used to specify the request body directly from flu.Input.
func (*RequestBuilder) ContentLength ¶ added in v0.10.5
func (r *RequestBuilder) ContentLength(contentLength int64) *RequestBuilder
ContentLength sets Content-Length header for this request. If not set, Content-Length header will be set automatically for request body io.Readers:
bytes.Buffer (flu.ByteBuffer) bytes.Reader (flu.Bytes) strings.Reader
Note that some servers may not accept unknown content length.
func (*RequestBuilder) ContentType ¶ added in v0.10.5
func (r *RequestBuilder) ContentType(contentType string) *RequestBuilder
ContentType sets Content-Type header for this request. If not set, Content-Type header will be set automatically if body implements ContentType interface.
func (*RequestBuilder) Exchange ¶ added in v0.10.5
func (r *RequestBuilder) Exchange(ctx context.Context, client Client) *ExchangeResult
Exchange executes the request and returns a response.
func (*RequestBuilder) Header ¶ added in v0.10.5
func (r *RequestBuilder) Header(key, value string) *RequestBuilder
Header set HTTP header for this request.
func (*RequestBuilder) Headers ¶ added in v0.10.5
func (r *RequestBuilder) Headers(kvPairs ...string) *RequestBuilder
func (*RequestBuilder) Method ¶ added in v0.10.5
func (r *RequestBuilder) Method(value string) *RequestBuilder
Method sets HTTP method for this request.
func (*RequestBuilder) Query ¶ added in v0.10.5
func (r *RequestBuilder) Query(key, value string) *RequestBuilder
Query sets a query parameter.
func (*RequestBuilder) QueryValues ¶ added in v0.10.5
func (r *RequestBuilder) QueryValues(values url.Values) *RequestBuilder
QueryValues sets query parameters from url.Values.
func (RequestBuilder) String ¶ added in v0.10.5
func (r RequestBuilder) String() string
type ResponseHandler ¶
ResponseHandler handles http.Response.
type ResponseHandlerFunc ¶ added in v0.10.5
ResponseHandlerFunc is ResponseHandler functional adapter.
type RoundTripperFunc ¶ added in v0.10.5
RoundTripperFunc is http.RoundTripper functional adapter.
type StatusCodeError ¶
type StatusCodeError struct { // StatusCode is the response status code. StatusCode int // Status is the response status. Status string }
StatusCodeError is returned when response status code does not match expected.
func (StatusCodeError) Error ¶
func (e StatusCodeError) Error() string
type VarargsLengthError ¶
type VarargsLengthError int
VarargsLengthError is returned when length of passed vararg is not even.
func (VarargsLengthError) Error ¶
func (e VarargsLengthError) Error() string
func (VarargsLengthError) Length ¶
func (e VarargsLengthError) Length() int