easyreq: github.com/nexneo/easyreq Index | Files

package easyreq

import "github.com/nexneo/easyreq"

Package easyreq provides support for creating requests easily for multipart form request or json API requests.

Usage import "github.com/nexneo/easyreq"

Form Example

f := easyreq.Form{}
f.Field().Add("Name", "John")
f.File().Add("File", "test-files/logo.png")
f.Header().Add("Host", "example.com")

req, err := f.Request("POST", "http://example.com/postform")

or

easyreq.NewForm(fields, nil).Do("GET", "http://example.com/")
easyreq.NewForm(fields, files).Do("POST", "http://example.com/")

Form will choose Content-Type based on any file added or not.

Json Example

j := easyreq.Json{}
j.Header().Add("Host", "example.com")
req, err := j.Set(v).Request("POST", "http://example.com/postjson")

or

req, err := easyreq.NewJson(v).Request("PUT", "http://example.com/putjson")

Index

Package Files

doc.go form.go json.go

type Form Uses

type Form struct {
    // contains filtered or unexported fields
}

Structure that contains form fields and upload files, can optionally have request headers.

func NewForm Uses

func NewForm(fields, files url.Values) *Form

Creates new Form with given fields and files

func (*Form) Do Uses

func (f *Form) Do(verb, urlStr string) (*http.Response, error)

Helper funcation send requests using http.DefaultClient

func (*Form) Field Uses

func (f *Form) Field() url.Values

Returns url.Values which should be used to Add form field

func (*Form) File Uses

func (f *Form) File() url.Values

Returns url.Values which should be used to Add form file

func (*Form) Header Uses

func (f *Form) Header() http.Header

func (*Form) Request Uses

func (form *Form) Request(verb, urlStr string) (*http.Request, error)

Returns request based on current Fields and Files assoicated with form Request will always have correct Content-Type set for POST and PUT

func (*Form) SetBasicAuth Uses

func (f *Form) SetBasicAuth(username, password string)

Helper to set Basic Auth header for request

type Json Uses

type Json struct {
    // contains filtered or unexported fields
}

func NewJson Uses

func NewJson(payload interface{}) *Json

func (*Json) Do Uses

func (j *Json) Do(verb, urlStr string) (*http.Response, error)

Helper funcation send requests using http.DefaultClient

func (*Json) Header Uses

func (j *Json) Header() http.Header

func (*Json) Request Uses

func (j *Json) Request(verb, urlStr string) (req *http.Request, err error)

Returns request based on current payload assoicated with Json request, it will always have correct Content-Type set

func (*Json) Set Uses

func (j *Json) Set(payload interface{}) *Json

func (*Json) SetBasicAuth Uses

func (j *Json) SetBasicAuth(username, password string)

type Requester Uses

type Requester interface {
    Header() http.Header
    Request(string, string) (*http.Request, error)
}

Inteface implemeted by Form, Json structures

Package easyreq imports 11 packages (graph) and is imported by 1 packages. Updated 2016-07-15. Refresh now. Tools for package owners.