rester

package module
v0.0.0-...-9005fa3 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2015 License: GPL-2.0 Imports: 3 Imported by: 0

README

Rester

master build test result

Rester is an micro rest api request lib. The base design is from restit.

Dependencies

Example


import github.com/Iceyer/rester

type User struct {
    Name  string
    Email string
}

func main() {
    apiURL = "https://api.iceyer.org/v0/test"
    restAPI := rester.Rest("User", apiURL)

    user := User{Name: "Iceyer", Email: "me@iceyer.net"}
    newUser := User{}
    req := restAPI.Create(&user).
        AddHeader("Access-Token", token).
        WithResponeAs(&newUser)

    result, err := req.Go()
    if nil != err {
        fmt.Println("Create User Failed")
    }
    fmt.Println("Request Status:", result.Status())
    fmt.Println("Create New User:", newUser)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Payload

type Payload interface {
	Equal(v interface{})
}

Payload is the essential interface for result check.

type Request

type Request struct {
	napping.Request

	Error interface{}
	// contains filtered or unexported fields
}

Request implement a simple interface for rest request

func (*Request) AddHeader

func (r *Request) AddHeader(key, value string) *Request

AddHeader will add a header params to request.

func (*Request) Go

func (r *Request) Go() (*napping.Response, error)

Go send the request

func (*Request) WithParams

func (r *Request) WithParams(p *url.Values) *Request

WithParams add query string params

func (*Request) WithResponeAs

func (r *Request) WithResponeAs(result interface{}) *Request

WithResponeAs set the body struct

type Rester

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

Rester is a instance to keep http info.

func Rest

func Rest(name string, url string) *Rester

Rest create an instance to send/recive data from rest server.

func (*Rester) Create

func (r *Rester) Create(payload interface{}) *Request

Create will return a new post request.

func (*Rester) Delete

func (r *Rester) Delete(id string) *Request

Delete object with the id.

func (*Rester) List

func (r *Rester) List(path string) *Request

List all object of special path, notice that / is the relative root and empty is the root path. Howerver, this request should return an array.

func (*Rester) Remove

func (r *Rester) Remove(path string) *Request

Remove objects under path. Notice that "" and "/" is not the same Url.

func (*Rester) Retrieve

func (r *Rester) Retrieve(id string) *Request

Retrieve object with the id.

func (*Rester) Update

func (r *Rester) Update(id string, payload interface{}) *Request

Update something of the id with the payload

type Session

type Session interface {
	Send(r *napping.Request) (*napping.Response, error)
}

Session is the wrapper of napping.Session.

Jump to

Keyboard shortcuts

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