Documentation
¶
Overview ¶
Package httpx provides an expressive framework to test http endpoints and handlers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Assertable ¶
Assertable defines a function that can take a slice of assertions and apply it on http.Response.
Although exported, user's won't be able to do much with this type. Instead they should use the ExpectIt(...) method to allow fluent chaining with MakeRequest(...).
func (Assertable) ExpectIt ¶
func (a Assertable) ExpectIt(t TestingT, assertions ...Assertion)
ExpectIt allows us to implement fluent chaining with MakeRequest(...). Use this method instead of directly invoking the Assertable to improve readability of your code.
type Assertion ¶
Assertion defines a function that performs some sort of assertion on the response to make sure that request was executed as expected.
type ExecFn ¶
ExecFn defines a function that can take an http.Request and return an http.Response (and optionally, an error).
This is the core type defined by this package and instances of this type does the actual heavy lifting work of making the request, receiving responses and more. How the actual execution is done is left to the implementation. Some may make actual http calls to remote endpoint whereas others would call in-memory http.Handler.
The core package provides two implementations that works with net/http package.
func (ExecFn) MakeRequest ¶
func (fn ExecFn) MakeRequest(factory RequestFactory, builders ...RequestBuilder) Assertable
MakeRequest is the primary entry point into the framework.
This method builds a request object, apply the given customisations / builders to it and then pass it to the ExecFn for execution returning an Assertable which you can then use to perform assertions on the response etc.
The core library provides certain general purpose builders. See RequestBuilder and it's implementations for more details on builders and how you can create a custom builder.
type RequestBuilder ¶
RequestBuilder defines a function that customises the request before it's sent out.
type RequestFactory ¶
RequestFactory defines a function capable of creating http.Request instances. Use of this type allows us to decouple MakeRequest(...) from the actual underlying mechanism of building an http.Request. Implementations of this type could (say) create instances configured for a PaaS (like Google App Engine) and more.
The core library provides a default implementation which should be sufficient for most use cases.
func Delete ¶
func Delete(url string) RequestFactory
Delete is a shorthand method to create a RequestFactory with http.MethodDelete
func Get ¶
func Get(url string) RequestFactory
Get is a shorthand method to create a RequestFactory with http.MethodGet
func Post ¶
func Post(url string, body io.Reader) RequestFactory
Post is a shorthand method to create a RequestFactory with http.MethodPost
Directories
¶
Path | Synopsis |
---|---|
Package assertions provides set of handy assertions for httpx.
|
Package assertions provides set of handy assertions for httpx. |
Package builders provides set of handy request builders for httpx.
|
Package builders provides set of handy request builders for httpx. |
Package executors provides default httpx.ExecFn based on Go standard library.
|
Package executors provides default httpx.ExecFn based on Go standard library. |