Skip to content


Repository files navigation

rq Build Status Go Report codecov

A nicer interface for golang stdlib HTTP client



Because golang HTTP client is a pain in the a...


  • Compatible with golang http stdlib: http.Request, http.Response and http.Cookie
  • Step by step to build your request
  • Better HTTP client
  • Better cookie jar
  • Import/export allow we save/transfer requests in JSON
  • Default setting: example default User-Agent or Accept-Language


go get -u

Getting started


import "net/http"
import ""

r := rq.Get("")

// query
r.Qs("q", "1", "2")
r.Qs("q", "3")
r.Qs("_", "123456")

// send with golang default HTTP client
res, err := http.DefaultClient.Do(r.ParseRequest())
defer res.Body.Close()

Custom client

In case you did not know that golang default http.Client has no timeout. use rq/client which has 180s timeout by default

import ""
import ""

r := rq.Post("")

// query
r.Qs("_", "123456")

// Form
r.Send("data", "data value")
r.Send("extra", "extra value")

// use default rq client
// true to tell #Send to read all the response boby when return
data, res, err := client.Send(r, true)
// no need to close res.Body
// read = false -> you need to call res.Body when done reading


r := rq.Post("")

r.Set("Content-Type", "application/json")
r.Set("User-Agent", "ddo/rq")

Raw body

r := rq.Post("")

r.SendRaw(strings.NewReader("raw data binary or json"))

Client Doc


// by default timeout = 3min
// no cookie jar
// and stops after 10 consecutive requests (10 redirects)
customClient := client.New(nil)

Custom Options

import ""

cookieJar := jar.New()

// custom timeout = 10s and cookie jar
customClient := client.New(&Option{
    Timeout: time.Second * 10,
    jar: cookieJar,

Default settings

// set default User-Agent
defaultRq := rq.Get("")
defaultRq.Set("User-Agent", "")

customClient := client.New(&Option{
    DefaultRq: defaultRq,

// from now all the requests called via this customClient
// gonna have the User-Agent header = ""
// if User-Agent header in request is not set


  • Default client stops after 10 consecutive requests
  • Or you can use client.NoRedirect to disable redirect
    CheckRedirect: client.NoCheckRedirect,

Cookies Doc

import ""

cookieJar := jar.New()

customClient := client.New(&client.Option{
    Jar: cookieJar,

// get all cookies by hostname
cookies, err := cookieJar.Get("")

// get a cookie by hostname and name
cookie, err := cookieJar.GetByName("", "cookiename").

// set cookies
err := cookieJar.Set("", cookies)

// set a cookie
err := cookieJar.SetOne("", cookie)

// clear the cookie jar
err := cookieJar.Clear("")

// delete a cookie by it's name
err := cookieJar.Delete("", "cookiename")


Set env DLOG=* to enable logger to see request activities


List here #1