greq

package module
v0.0.0-...-5147740 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2014 License: MIT Imports: 9 Imported by: 10

README

greq

Very simple go http request library. Every method returns the string body, http.Response, and err.

Supported Methods

There is a more generic Do function. But the following wrappers will be easier.

  • Get
  • Post
  • Put
  • Delete

Usage

import ("github.com/gwoo/greq")
req := greq.New("http://google.com", false) //Use form-encoded data. If true, use json body.
body, response, err := req.Get("/")

var data map[string]interface{}
body, response, err := req.Post("/search", data{"q": "sailboats"})

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do(method string, url string, headers http.Header, body io.Reader) ([]byte, *http.Response, error)

Generic request method

func ToForm

func ToForm(data map[string]interface{}) url.Values

Conver a map[string]interface to url.Values

Types

type Req

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

Req object

func New

func New(host string, json bool) *Req

Get a new req object.

func (*Req) Delete

func (r *Req) Delete(path string) ([]byte, *http.Response, error)

Send delete to the path on the host.

func (*Req) Get

func (r *Req) Get(path string) ([]byte, *http.Response, error)

Get the path from the host.

func (*Req) Head

func (r *Req) Head(path string) ([]byte, *http.Response, error)

Send head to the host.

func (*Req) Header

func (r *Req) Header(h http.Header) http.Header

func (*Req) Options

func (r *Req) Options(path string) ([]byte, *http.Response, error)

Get the options from the host.

func (*Req) Post

func (r *Req) Post(path string, data map[string]interface{}) ([]byte, *http.Response, error)

Post data to the path on the host.

func (*Req) Put

func (r *Req) Put(path string, data map[string]interface{}) ([]byte, *http.Response, error)

Put data to the path on the host.

Jump to

Keyboard shortcuts

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