Documentation ¶
Overview ¶
Package esrest implements functions to wrapper around the HTTP client API.
Index ¶
- Constants
- type Builder
- func (b *Builder) BasicAuth(username, password string) *Builder
- func (b *Builder) Body(v interface{}) *Builder
- func (b *Builder) Debug(debug bool) *Builder
- func (b *Builder) Delete(url string) *Builder
- func (b *Builder) Do() (*http.Response, error)
- func (b *Builder) DoJson(v interface{}) (*http.Response, error)
- func (b *Builder) Get(url string) *Builder
- func (b *Builder) Head(url string) *Builder
- func (b *Builder) Header(key, value string) *Builder
- func (b *Builder) Logger(log *log.Logger) *Builder
- func (b *Builder) Post(url string) *Builder
- func (b *Builder) Put(url string) *Builder
- func (b *Builder) Query(key, value string) *Builder
- func (b *Builder) Timeout(timeout time.Duration) *Builder
Constants ¶
View Source
const DefaultContentType = "application/json"
DefaultContentType is default http Content-Type="application/json" header.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder struct { Url string Method string Path string Headers map[string]string Querys map[string]string DebugMode bool // contains filtered or unexported fields }
Builder is a object that help to build fluent style API.
func (*Builder) Body ¶
Body is used to set the HTTP request body to send payload(JSON/string/slice/pointer) when "Do()" or "DoJson()" func is called.
For Example, Set JSON struct as the request body:
res, err := esrest.New(). Post("http://httpbin.org/post"). Body(struct { Message string `json:"message"` }{"ok"}). Do()
Set JSON struct pointer as the request body:
res, err := esrest.New(). Post("http://httpbin.org/post"). Body(&struct { Message string `json:"message"` }{"ok"}). Do()
Set bytes slice as the request body:
res, err := esrest.New(). Post("http://httpbin.org/post"). Body([]byte(`{"message":"ok"}`)). Do()
Set HTTP request body as string:
es, err := esrest.New(). Post("http://httpbin.org/post"). Body(string(`{"message":"ok"}`)). Do()
Set HTTP request body as map:
m := map[string]interface{}{ "message": "ok", } res, err := esrest.New(). Post("http://httpbin.org/post"). Body(m). Do()
func (*Builder) DoJson ¶
DoJson executes the http request client and returns http.Response and error.
Click to show internal directories.
Click to hide internal directories.