Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
edoger committed Dec 11, 2020
1 parent b62d382 commit b6c8f2b
Showing 1 changed file with 41 additions and 60 deletions.
101 changes: 41 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,83 +2,64 @@

[![ZKits](https://img.shields.io/badge/ZKits-Library-f3c)](https://github.com/edoger/zkits-requester)
[![Build Status](https://travis-ci.org/edoger/zkits-requester.svg?branch=master)](https://travis-ci.org/edoger/zkits-requester)
[![Build status](https://ci.appveyor.com/api/projects/status/0hreadwn4rb9mkw2/branch/master?svg=true)](https://ci.appveyor.com/project/edoger56924/zkits-requester/branch/master)
[![Coverage Status](https://coveralls.io/repos/github/edoger/zkits-requester/badge.svg?branch=master)](https://coveralls.io/github/edoger/zkits-requester?branch=master)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/8da10a218dbe4700bcbb409718538fab)](https://www.codacy.com/gh/edoger/zkits-requester/dashboard?utm_source=github.com&utm_medium=referral&utm_content=edoger/zkits-requester&utm_campaign=Badge_Grade)
[![Go Report Card](https://goreportcard.com/badge/github.com/edoger/zkits-requester)](https://goreportcard.com/report/github.com/edoger/zkits-requester)
[![Golang Version](https://img.shields.io/badge/golang-1.14+-orange)](https://github.com/edoger/zkits-requester)

## About ##

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

## Install ##

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

## Usage ##
```go
package main

import (
"fmt"

1. Import package.

```sh
go get -u -v github.com/edoger/zkits-requester
```
"github.com/edoger/zkits-requester"
)

2. Create a client to send some requests.
func main() {
client := requester.Default()

```go
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)
}
var obj interface{}
// Bind response json to object.
if err = res.JSON(&obj); err != nil {
panic(err)
}
// client.Get("https://test.com", nil)
res, err := client.New("https://test.com").Get()
if err != nil {
panic(err)
}
```
fmt.Println(res.String())

3. Upload file.
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)
}

```go
package main
import (
"fmt"
"github.com/edoger/zkits-requester"
)
func main() {
client := requester.Default()
// 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())
// 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 ##

Expand Down

0 comments on commit b6c8f2b

Please sign in to comment.