Skip to content

chyroc/gorequests

Repository files navigation

gorequests

codecov go report card test status Apache-2.0 license Go.Dev reference Go project version

Simple and easy-to-use go http client, supports cookies, streaming calls, custom logs and other functions

Install

go get github.com/chyroc/gorequests

Usage

Simple Send Request

func main() {
	text, err := gorequests.New(http.MethodGet, "https://jsonplaceholder.typicode.com/todos/1").Text()
	if err != nil {
		panic(err)
	}
	fmt.Println("text", text)
}

Send Request With Cookie

func main() {
	session := gorequests.NewSession("/tmp/gorequests-session.txt")
	text, err := session.New(http.MethodGet, "https://jsonplaceholder.typicode.com/todos/1").Text()
	if err != nil {
		panic(err)
	}
	fmt.Println("text", text)
}

Request Factory

func main() {
    fac := gorequests.NewFactory(
        gorequests.WithLogger(gorequests.NewDiscardLogger()),
    )
	text, err := fac.New(http.MethodGet, "https://jsonplaceholder.typicode.com/todos/1").Text()
	if err != nil {
		panic(err)
	}
	fmt.Println("text", text)
}