Documentation ¶
Overview ¶
Package httpdriver provides interfaces and implementations of a simple HTTP client.
Index ¶
Constants ¶
const NoContent = 204
NoContent is the status code for HTTP 204, or http.StatusNoContent.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type Client interface { NewRequest(ctx context.Context, method, url string) (Request, error) Do(req Request) (Response, error) }
Client is a generic interface used as an adapter allowing for custom HTTP client implementations, such as fasthttp.
func NewClient ¶
func NewClient() Client
NewClient creates a new client around the standard library's http.Client. The client will have a timeout of 10 seconds.
func WrapClient ¶
WrapClient wraps around the standard library's http.Client and returns an implementation that's compatible with the Client driver interface.
type DefaultClient ¶
DefaultClient implements Client and wraps around the stdlib Client.
func (DefaultClient) NewRequest ¶
type DefaultRequest ¶
DefaultRequest wraps around the stdlib Request and satisfies the Request interface.
func (*DefaultRequest) AddHeader ¶
func (r *DefaultRequest) AddHeader(header http.Header)
func (*DefaultRequest) AddQuery ¶
func (r *DefaultRequest) AddQuery(values url.Values)
func (*DefaultRequest) GetContext ¶
func (r *DefaultRequest) GetContext() context.Context
func (*DefaultRequest) GetPath ¶
func (r *DefaultRequest) GetPath() string
func (*DefaultRequest) WithBody ¶
func (r *DefaultRequest) WithBody(body io.ReadCloser)
type DefaultResponse ¶
DefaultResponse wraps around the stdlib Response and satisfies the Response interface.
func (*DefaultResponse) GetBody ¶
func (r *DefaultResponse) GetBody() io.ReadCloser
func (*DefaultResponse) GetHeader ¶
func (r *DefaultResponse) GetHeader() http.Header
func (*DefaultResponse) GetStatus ¶
func (r *DefaultResponse) GetStatus() int
type Request ¶
type Request interface { // GetPath should return the URL path, for example "/endpoint/thing". GetPath() string // GetContext should return the same context that's passed into NewRequest. // For implementations that don't support this, it can remove a // context.Background(). GetContext() context.Context // AddHeader appends headers. AddHeader(http.Header) // AddQuery appends URL query values. AddQuery(url.Values) // WithBody should automatically close the ReadCloser on finish. This is // similar to the stdlib's Request behavior. WithBody(io.ReadCloser) }
Request is a generic interface for a normal HTTP request. It should be constructed using (Requester).NewRequest().