Documentation ¶
Index ¶
- Constants
- Variables
- func AddMockups(mocks ...*Mock) error
- func AsyncDelete(url string, f func(*Response))
- func AsyncGet(url string, f func(*Response))
- func AsyncHead(url string, f func(*Response))
- func AsyncOptions(url string, f func(*Response))
- func AsyncPatch(url string, body interface{}, f func(*Response))
- func AsyncPost(url string, body interface{}, f func(*Response))
- func AsyncPut(url string, body interface{}, f func(*Response))
- func FlushMockups()
- func ForkJoin(f func(*Concurrent))
- func StartMockupServer()
- func StopMockupServer()
- type BasicAuth
- type ByteSize
- type Concurrent
- func (c *Concurrent) Delete(url string) *FutureResponse
- func (c *Concurrent) Get(url string) *FutureResponse
- func (c *Concurrent) Head(url string) *FutureResponse
- func (c *Concurrent) Options(url string) *FutureResponse
- func (c *Concurrent) Patch(url string, body interface{}) *FutureResponse
- func (c *Concurrent) Post(url string, body interface{}) *FutureResponse
- func (c *Concurrent) Put(url string, body interface{}) *FutureResponse
- type ContentType
- type CustomPool
- type FutureResponse
- type Mock
- type RequestBuilder
- func (rb *RequestBuilder) AsyncDelete(url string, f func(*Response))
- func (rb *RequestBuilder) AsyncGet(url string, f func(*Response))
- func (rb *RequestBuilder) AsyncHead(url string, f func(*Response))
- func (rb *RequestBuilder) AsyncOptions(url string, f func(*Response))
- func (rb *RequestBuilder) AsyncPatch(url string, body interface{}, f func(*Response))
- func (rb *RequestBuilder) AsyncPost(url string, body interface{}, f func(*Response))
- func (rb *RequestBuilder) AsyncPut(url string, body interface{}, f func(*Response))
- func (rb *RequestBuilder) Delete(url string) *Response
- func (rb *RequestBuilder) ForkJoin(f func(c *Concurrent))
- func (rb *RequestBuilder) Get(url string) *Response
- func (rb *RequestBuilder) Head(url string) *Response
- func (rb *RequestBuilder) Options(url string) *Response
- func (rb *RequestBuilder) Patch(url string, body interface{}) *Response
- func (rb *RequestBuilder) Post(url string, body interface{}) *Response
- func (rb *RequestBuilder) Put(url string, body interface{}) *Response
- type Response
Constants ¶
const MockNotFoundError string = "MockUp nil!"
MockNotFoundError ...
Variables ¶
var DefaultConnectTimeout = 1500 * time.Millisecond
DefaultConnectTimeout ...
var DefaultMaxIdleConnsPerHost = 2
DefaultMaxIdleConnsPerHost is the default maxium idle connections to have per Host for all clients, that use *any* RequestBuilder that don't set a CustomPool
var DefaultTimeout = 500 * time.Millisecond
DefaultTimeout is the default timeout for all clients. DefaultConnectTimeout is the time it takes to make a connection Type: time.Duration
var MaxCacheSize = 1 * GB
MaxCacheSize is the maximum byte size to be hold the ResourceCache Default is 1 Gigabyte Type: rest.ByteSize
Functions ¶
func AsyncDelete ¶
AsyncDelete is the *asynchronous* option for DELETE. The go routine calling AsyncGet(), will not be blocked.
Whenever the Response is ready, the *f* function will be called back.
AsyncDelete uses the DefaultBuilder
func AsyncGet ¶
AsyncGet is the *asynchronous* option for GET. The go routine calling AsyncGet(), will not be blocked.
Whenever the Response is ready, the *f* function will be called back.
AsyncGet uses the DefaultBuilder
func AsyncHead ¶
AsyncHead is the *asynchronous* option for HEAD. The go routine calling AsyncGet(), will not be blocked.
Whenever the Response is ready, the *f* function will be called back.
AsyncHead uses the DefaultBuilder
func AsyncOptions ¶
AsyncOptions is the *asynchronous* option for OPTIONS. The go routine calling AsyncGet(), will not be blocked.
Whenever the Response is ready, the *f* function will be called back.
AsyncOptions uses the DefaultBuilder
func AsyncPatch ¶
AsyncPatch is the *asynchronous* option for PATCH. The go routine calling AsyncGet(), will not be blocked.
Whenever the Response is ready, the *f* function will be called back.
AsyncPatch uses the DefaultBuilder
func AsyncPost ¶
AsyncPost is the *asynchronous* option for POST. The go routine calling AsyncGet(), will not be blocked.
Whenever the Response is ready, the *f* function will be called back.
AsyncPost uses the DefaultBuilder
func AsyncPut ¶
AsyncPut is the *asynchronous* option for PUT. The go routine calling AsyncGet(), will not be blocked.
Whenever the Response is ready, the *f* function will be called back.
AsyncPut uses the DefaultBuilder
func ForkJoin ¶
func ForkJoin(f func(*Concurrent))
ForkJoin let you *fork* requests, and *wait* until all of them have return.
func StartMockupServer ¶
func StartMockupServer()
StartMockupServer sets the enviroment to send all client requests to the mockup server.
func StopMockupServer ¶
func StopMockupServer()
StopMockupServer stop sending requests to the mockup server
Types ¶
type Concurrent ¶
type Concurrent struct {
// contains filtered or unexported fields
}
Concurrent implements methods for HTTP verbs. The difference with synchronous API is that concurrent methods return a FutureResponse which hold a pointer to a Response, which is nil until the request has finished.
func (*Concurrent) Delete ¶
func (c *Concurrent) Delete(url string) *FutureResponse
Delete perform a DELETE HTTP verb to the specified URL concurrently.
func (*Concurrent) Get ¶
func (c *Concurrent) Get(url string) *FutureResponse
Get perform a GET HTTP verb to the specified URL concurrently.
func (*Concurrent) Head ¶
func (c *Concurrent) Head(url string) *FutureResponse
Head perform a HEAD HTTP verb to the specified URL concurrently.
func (*Concurrent) Options ¶
func (c *Concurrent) Options(url string) *FutureResponse
Options perform a OPTIONS HTTP verb to the specified URL concurrently.
func (*Concurrent) Patch ¶
func (c *Concurrent) Patch(url string, body interface{}) *FutureResponse
Patch perform a PATCH HTTP verb to the specified URL concurrently.
Body could be any of the form: string, []byte, struct & map.
func (*Concurrent) Post ¶
func (c *Concurrent) Post(url string, body interface{}) *FutureResponse
Post perform a POST HTTP verb to the specified URL concurrently.
Body could be any of the form: string, []byte, struct & map.
func (*Concurrent) Put ¶
func (c *Concurrent) Put(url string, body interface{}) *FutureResponse
Put perform a PUT HTTP verb to the specified URL concurrently.
Body could be any of the form: string, []byte, struct & map.
type ContentType ¶
type ContentType int
ContentType represents the HTTP Vebs body's type
const ( // JSON represents a JSON content type JSON ContentType = iota // XML represents an XML content type XML // BYTES represents a plain content type BYTES )
type CustomPool ¶
type CustomPool struct { MaxIdleConnsPerHost int Proxy string // Public for custom fine tuning Transport http.RoundTripper }
CustomPool defines a separated internal *transport* and connection pooling.
type FutureResponse ¶
type FutureResponse struct {
// contains filtered or unexported fields
}
FutureResponse represents a response to be completed after a ForkJoin operation is done
FutureResponse will never be nil and has a Response fucntion for getting the Response that will be nil after the ForkJoin operation is completed.
func (*FutureResponse) Response ¶
func (fr *FutureResponse) Response() *Response
Response gives you the Response of a Request after the ForkJoin operation is completed. Response will be nil if the ForkJoin operation is not completed.
type Mock ¶
type Mock struct { // Request URL URL string // Request HTTP Method (GET, POST, PUT, PATCH, HEAD, DELETE, OPTIONS) // As a good practice use the constants in http package (http.MethodGet, etc.) HTTPMethod string // Request array Headers ReqHeaders http.Header // Request Body, used with POST, PUT & PATCH ReqBody string // Response HTTP Code RespHTTPCode int // Response Array Headers RespHeaders http.Header // Response Body RespBody string }
Mock serves the purpose of creating Mockups. All requests will be sent to the mockup server if mockup is activated. To activate the mockup *environment* you have to programmatically start the mockup server
Or by programmatically starting the mockup server
StartMockupServer()
type RequestBuilder ¶
type RequestBuilder struct { // Headers to be send in the request. Headers http.Header // Timeout to complete request Timeout time.Duration // ConnectionTimeout bounds the time spent obtaining a successful connection ConnectionTimeout time.Duration // Base url is used to build the entire url for make the request (BaseURL + URI) BaseURL string // ContentType ContentType ContentType // Disable internal caching of response DisableCache bool // Disable timeout. DisableTimeout bool // Set the http client to follow a redirect if it gets a 3xx response from the server FollowRedirect bool // CustomPool create a pool if you don't want to share the *transport*, with others RequestBuilders CustomPool *CustomPool // Set basic Auth created request BasicAuth *BasicAuth // Set a specific user agent for the created request UserAgent string // Public for custom fine tuning Client *http.Client // contains filtered or unexported fields }
RequestBuilder is the baseline to create requests There is a DefaultBuilder that you may use for simple requests RequestBuilder is thread-safe and should be stored for later usage.
func (*RequestBuilder) AsyncDelete ¶
func (rb *RequestBuilder) AsyncDelete(url string, f func(*Response))
AsyncDelete ...
func (*RequestBuilder) AsyncGet ¶
func (rb *RequestBuilder) AsyncGet(url string, f func(*Response))
AsyncGet ...
func (*RequestBuilder) AsyncHead ¶
func (rb *RequestBuilder) AsyncHead(url string, f func(*Response))
AsyncHead ...
func (*RequestBuilder) AsyncOptions ¶
func (rb *RequestBuilder) AsyncOptions(url string, f func(*Response))
AsyncOptions ...
func (*RequestBuilder) AsyncPatch ¶
func (rb *RequestBuilder) AsyncPatch(url string, body interface{}, f func(*Response))
AsyncPatch ...
func (*RequestBuilder) AsyncPost ¶
func (rb *RequestBuilder) AsyncPost(url string, body interface{}, f func(*Response))
AsyncPost ...
func (*RequestBuilder) AsyncPut ¶
func (rb *RequestBuilder) AsyncPut(url string, body interface{}, f func(*Response))
AsyncPut ...
func (*RequestBuilder) ForkJoin ¶
func (rb *RequestBuilder) ForkJoin(f func(c *Concurrent))
ForkJoin let you *fork* requests, and *wait* until all of them have return.
var futureA, futureB *rest.FutureResponse rest.ForkJoin(func(c *rest.Concurrent){ futureA = c.Get("/url/1") futureB = c.Get("/url/2") }) fmt.Println(futureA.Response()) fmt.Println(futureB.Response())
func (*RequestBuilder) Options ¶
func (rb *RequestBuilder) Options(url string) *Response
Options ...
func (*RequestBuilder) Patch ¶
func (rb *RequestBuilder) Patch(url string, body interface{}) *Response
Patch ...
func (*RequestBuilder) Post ¶
func (rb *RequestBuilder) Post(url string, body interface{}) *Response
Post ...
func (*RequestBuilder) Put ¶
func (rb *RequestBuilder) Put(url string, body interface{}) *Response
Put ...
type Response ¶
Response structure
func Delete ¶
Delete handles a DELETE HTTP verb to an specified URL.
In RESTful, DELETE is used to "delete" an specified resource from the server. Client should expect a response status code of 200(OK), 400(Bad Request), 401(Unauthorized), 403(Forbiden), 404(Not Found), 405(Method Not Allowed).
Delete uses the DefaultBuilder.
func Get ¶
Get handles a GET HTTP verb to an specified URL.
In RESTful, GET is used for "reading" or retrieving a resource. Client should expect a response status code of 200(OK) if resource exists, 404(Not Found) if it doesn't, or 400(Bad Request).
Get uses the DefaultBuilder.
func Head ¶
Head issues a HEAD HTTP verb to the specified URL
In Restful, HEAD is used to "read" a resource headers only. Client should expect a response status code of 200(OK) if resource exists, 404(Not Found) if it doesn't, or 400(Bad Request).
Head uses the DefaultBuilder.
func Options ¶
Options issues a OPTIONS HTTP verb to the specified URL
In Restful, OPTIONS is used to get information about the resource and supported HTTP verbs. Client should expect a response status code of 200(OK) if resource exists, 404(Not Found) if it doesn't, or 400(Bad Request).
func Patch ¶
Patch issues a PATCH HTTP verb to the specified URL
In Restful, PATCH is used for "partially updating" a resource. Client should expect a response status code of of 200(OK), 404(Not Found), or 400(Bad Request). 200(OK) could be also 204(No Content)
Body could be any of the form: string, []byte, struct & map.
Patch uses the DefaultBuilder.
func Post ¶
Post handles a POST HTTP verb to an specified URL.
In RESTful, POST is used to send user-generated data to the server. This data is stored in a subordinate of the resourse identified in the Request-URI. In other words, POST append a resourse at the end of a given url. Client should expect a response status code of 201(Created), 400(Bad Request), 404(Not Found), 405(Method Not Allowed) or 409(Conflict) if resource already exist.
Body could be any of the form: string, []byte, struct & map.
func Put ¶
Put handles a PUT HTTP verb to an specified URL
In RESTful, PUT is used to send user-generated data to the server. Knowing the exact URI of the resourse, it creates it or, if the resourse already exists it ovewrites it with the Request-body data. PUT verb is idempotent, it means that if you apply it n times it will always return the same result. Client should expect a response status code of 200(OK), 201(Created), 204(No Content), 400(Bad Request), 404(Not Found), 405(Method Not Allowed).
Body could be any of the form: string, []byte, struct & map.
Put uses the DefaultBuilder.
func (*Response) Debug ¶
Debug let any req/res to be dumped, showing how the req/res went through the wire, only if debug mode is *on* on RequestBuilder