easyreq

package module
v0.0.0-...-53838f9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 28, 2015 License: BSD-3-Clause Imports: 11 Imported by: 0

README

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

Usage

Check usage and API docs at http://godoc.org/github.com/nexneo/easyreq

GoDoc

Documentation

Overview

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Form

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

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

func NewForm

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

Creates new Form with given fields and files

func (*Form) Do

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

Helper funcation send requests using http.DefaultClient

func (*Form) Field

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

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

func (*Form) File

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

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

func (*Form) Header

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

func (*Form) Request

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

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

Helper to set Basic Auth header for request

type Json

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

func NewJson

func NewJson(payload interface{}) *Json

func (*Json) Do

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

Helper funcation send requests using http.DefaultClient

func (*Json) Header

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

func (*Json) Request

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

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

func (*Json) SetBasicAuth

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

type Requester

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

Inteface implemeted by Form, Json structures

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL