Skip to content

edoger/zkits-requester

Repository files navigation

ZKits Requester Library

ZKits Build Status Build status Coverage Status Codacy Badge Go Report Card Golang Version

About

This package is a library of ZKits project. This library provides an efficient and easy-to-use HTTP client.

Install

go get -u -v github.com/edoger/zkits-requester

Usage

package main

import (
    "fmt"

    "github.com/edoger/zkits-requester"
)

func main() {
    client := requester.Default()

    // client.Get("https://test.com", nil)
    res, err := client.New("https://test.com").Get()
    if err != nil {
        panic(err)
    }
    fmt.Println(res.String())

    data := map[string]interface{}{"key": "value"}
    // client.PostJSON("https://test.com", data)
    res, err = client.New("https://test.com").WithJSONBody(data).Post()
    if err != nil {
        panic(err)
    }

    obj := make(map[string]interface{})
    // Bind response json to object.
    if err = res.JSON(&obj); err != nil {
        panic(err)
    }

    // client.UploadFile("https://test.com", "upload", "path/to/file")
    res, err = client.New("https://test.com").WithFormDataFile("upload", "path/to/file").Upload()
    if err != nil {
        panic(err)
    }
    fmt.Println(res.String())
}

License

Apache-2.0