All Projects → idoubi → Goz

idoubi / Goz

Licence: mit
A fantastic HTTP request libarary used in Golang.

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Goz

Request
A simple PHP HTTP request class.
Stars: ✭ 49 (-73.8%)
Mutual labels:  curl, request
request-extra
⚡️ Extremely stable HTTP request module built on top of libcurl with retries, timeouts and callback API
Stars: ✭ 14 (-92.51%)
Mutual labels:  curl, request
HttpRequest
Simplified HTTP client, A simplie golang HTTP client library.
Stars: ✭ 134 (-28.34%)
Mutual labels:  curl, request
Urllib
Request HTTP(s) URLs in a complex world
Stars: ✭ 600 (+220.86%)
Mutual labels:  curl, request
go-axios
HTTP Request package for golang.
Stars: ✭ 29 (-84.49%)
Mutual labels:  curl, request
Http Client
A high-performance, high-stability, cross-platform HTTP client.
Stars: ✭ 86 (-54.01%)
Mutual labels:  curl, request
Curl To Csharp
curl to C# converter
Stars: ✭ 153 (-18.18%)
Mutual labels:  curl
Gdrive.sh
Download a file or a folder easily. curl gdrive.sh | bash -s $fileid
Stars: ✭ 164 (-12.3%)
Mutual labels:  curl
Use Http
🐶 React hook for making isomorphic http requests
Stars: ✭ 2,066 (+1004.81%)
Mutual labels:  request
Httpp
Micro http server and client written in C++
Stars: ✭ 144 (-22.99%)
Mutual labels:  curl
Bodyclose
Analyzer: checks whether HTTP response body is closed and a re-use of TCP connection is not blocked.
Stars: ✭ 181 (-3.21%)
Mutual labels:  request
Zebra curl
A high performance cURL PHP library for running of multiple requests at once, asynchronously
Stars: ✭ 172 (-8.02%)
Mutual labels:  curl
Examples
Examples of Mock Service Worker usage with various frameworks and libraries.
Stars: ✭ 163 (-12.83%)
Mutual labels:  request
Curlsharp
CurlSharp - .Net binding and object-oriented wrapper for libcurl.
Stars: ✭ 153 (-18.18%)
Mutual labels:  curl
Libhv
🔥 比libevent、libuv更易用的国产网络库。A c/c++ network library for developing TCP/UDP/SSL/HTTP/WebSocket client/server.
Stars: ✭ 3,355 (+1694.12%)
Mutual labels:  curl
Holen
Declarative fetch for React
Stars: ✭ 152 (-18.72%)
Mutual labels:  request
Insta Mass Account Creator
User Friendly - Instagram Auto Account Creation Bot 🤖
Stars: ✭ 173 (-7.49%)
Mutual labels:  request
Knproxy
Lightweight, PHP-based Web Proxy that can utilize whatever remote connecting ablities your server has to offer. It should work out of the box. No configuration needed. For educational purposes.
Stars: ✭ 148 (-20.86%)
Mutual labels:  curl
Restrequest4delphi
API to consume REST services written in any programming language with support to Lazarus and Delphi
Stars: ✭ 162 (-13.37%)
Mutual labels:  request
J2team Community
Join our group to see more
Stars: ✭ 172 (-8.02%)
Mutual labels:  curl

goz

A fantastic HTTP request library used in golang. Inspired by guzzle

Installation

go get -u github.com/idoubi/goz

Documentation

API documentation can be found here: https://godoc.org/github.com/idoubi/goz

Basic Usage

package main

import (
    "github.com/idoubi/goz"
)

func main() {
    cli := goz.NewClient()

	resp, err := cli.Get("http://127.0.0.1:8091/get")
	if err != nil {
		log.Fatalln(err)
	}

	fmt.Printf("%T", resp)
	// Output: *goz.Response
}

Query Params

  • query map
cli := goz.NewClient()

resp, err := cli.Get("http://127.0.0.1:8091/get-with-query", goz.Options{
    Query: map[string]interface{}{
        "key1": "value1",
        "key2": []string{"value21", "value22"},
        "key3": "333",
    },
})
if err != nil {
    log.Fatalln(err)
}

fmt.Printf("%s", resp.GetRequest().URL.RawQuery)
// Output: key1=value1&key2=value21&key2=value22&key3=333
  • query string
cli := goz.NewClient()

resp, err := cli.Get("http://127.0.0.1:8091/get-with-query?key0=value0", goz.Options{
    Query: "key1=value1&key2=value21&key2=value22&key3=333",
})
if err != nil {
    log.Fatalln(err)
}

fmt.Printf("%s", resp.GetRequest().URL.RawQuery)
// Output: key1=value1&key2=value21&key2=value22&key3=333

Post Data

  • post form
cli := goz.NewClient()

resp, err := cli.Post("http://127.0.0.1:8091/post-with-form-params", goz.Options{
    Headers: map[string]interface{}{
        "Content-Type": "application/x-www-form-urlencoded",
    },
    FormParams: map[string]interface{}{
        "key1": "value1",
        "key2": []string{"value21", "value22"},
        "key3": "333",
    },
})
if err != nil {
    log.Fatalln(err)
}

body, _ := resp.GetBody()
fmt.Println(body)
// Output: form params:{"key1":["value1"],"key2":["value21","value22"],"key3":["333"]}
  • post json
cli := goz.NewClient()

resp, err := cli.Post("http://127.0.0.1:8091/post-with-json", goz.Options{
    Headers: map[string]interface{}{
        "Content-Type": "application/json",
    },
    JSON: struct {
        Key1 string   `json:"key1"`
        Key2 []string `json:"key2"`
        Key3 int      `json:"key3"`
    }{"value1", []string{"value21", "value22"}, 333},
})
if err != nil {
    log.Fatalln(err)
}

body, _ := resp.GetBody()
fmt.Println(body)
// Output: json:{"key1":"value1","key2":["value21","value22"],"key3":333}

Request Headers

cli := goz.NewClient()

resp, err := cli.Post("http://127.0.0.1:8091/post-with-headers", goz.Options{
    Headers: map[string]interface{}{
        "User-Agent": "testing/1.0",
        "Accept":     "application/json",
        "X-Foo":      []string{"Bar", "Baz"},
    },
})
if err != nil {
    log.Fatalln(err)
}

headers := resp.GetRequest().Header["X-Foo"]
fmt.Println(headers)
// Output: [Bar Baz]

Response

cli := goz.NewClient()
resp, err := cli.Get("http://127.0.0.1:8091/get")
if err != nil {
    log.Fatalln(err)
}

body, err := resp.GetBody()
if err != nil {
    log.Fatalln(err)
}
fmt.Printf("%T", body)
// Output: goz.ResponseBody

part := body.Read(30)
fmt.Printf("%T", part)
// Output: []uint8

contents := body.GetContents()
fmt.Printf("%T", contents)
// Output: string

fmt.Println(resp.GetStatusCode())
// Output: 200

fmt.Println(resp.GetReasonPhrase())
// Output: OK

headers := resp.GetHeaders()
fmt.Printf("%T", headers)
// Output: map[string][]string

flag := resp.HasHeader("Content-Type")
fmt.Printf("%T", flag)
// Output: bool

header := resp.GetHeader("content-type")
fmt.Printf("%T", header)
// Output: []string
    
headerLine := resp.GetHeaderLine("content-type")
fmt.Printf("%T", headerLine)
// Output: string

Proxy

cli := goz.NewClient()

resp, err := cli.Get("https://www.fbisb.com/ip.php", goz.Options{
    Timeout: 5.0,
    Proxy:   "http://127.0.0.1:1087",
})
if err != nil {
    log.Fatalln(err)
}

fmt.Println(resp.GetStatusCode())
// Output: 200

Timeout

cli := goz.NewClient(goz.Options{
    Timeout: 0.9,
})
resp, err := cli.Get("http://127.0.0.1:8091/get-timeout")
if err != nil {
    if resp.IsTimeout() {
        fmt.Println("timeout")
        // Output: timeout
        return
    }
}

fmt.Println("not timeout")

License

MIT

Copyright (c) 2017-present, idoubi

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].