jsonclient

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

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

Go to latest
Published: Nov 22, 2015 License: MIT Imports: 0 Imported by: 0

README

Json Client

A Json-input / JsonObject-output client.

how to use

get

$ go get github.com/mokelab-go/jsonclient

write

package main

import (
        "fmt"
        jc "github.com/mokelab-go/jsonclient/http"
)

func main() {
        client := jc.NewClient()
        client.SetURL("https://api-jp.kii.com/api/oauth2/token")
        client.SetMethod("POST")
        client.SetHeader("x-kii-appid", "aa")
        client.SetHeader("x-kii-appkey", "bb")
        resp, err := client.Send(map[string]interface{}{
                "username": "fkm",
                "password": "123456",
        })
        if err != nil {
                fmt.Printf("Error : %s\n", err)
                return
        }
        fmt.Printf("Status = %d\n", resp.Status)
        fmt.Printf("Response headers\n")
        for key, value := range resp.Headers {
                fmt.Printf("%s = %s\n", key, value)
        }
        fmt.Printf("Response body\n")
        // resp.Body is map[string]interface{}
        fmt.Printf("%s", resp.Body)
}

Documentation

Index

Constants

View Source
const (
	METHOD_GET    = "GET"
	METHOD_POST   = "POST"
	METHOD_PUT    = "PUT"
	METHOD_DELETE = "DELETE"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	SetURL(url string)
	SetMethod(method string)
	SetHeader(key, value string)
	Send(body map[string]interface{}) (Response, error)
}

type Response

type Response struct {
	Status  int
	Headers map[string]string
	Body    map[string]interface{}
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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