MCPcopy Index your code
hub / github.com/ddo/rq

github.com/ddo/rq @0.0.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release 0.0.1 ↗ · + Follow
78 symbols 297 edges 17 files 35 documented · 45%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

rq

A nicer interface for golang stdlib HTTP client

Doc Build Status Go Report codecov

Why?

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

Features

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

Documents

Installation

go get -u gopkg.in/ddo/rq.v0

Getting started

Simple

import "net/http"
import "github.com/ddo/rq"

r := rq.Get("https://httpbin.org/get")

// query https://httpbin.org/get?q=1&q=2&q=3&_=123456
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 "github.com/ddo/rq"
import "github.com/ddo/rq/client"

r := rq.Post("https://httpbin.org/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

Headers

r := rq.Post("https://httpbin.org/post")

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

Raw body

r := rq.Post("https://httpbin.org/post")

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

Client Doc

Default

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

Custom Options

// custom timeout = 10s and no cookie jar
customClient := client.New(&Option{
    Timeout: time.Second * 10,
    NoCookie: true,
})

Default settings

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

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

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

Redirect

  • Default client stops after 10 consecutive requests
  • Or you can use client.NoRedirect to disable redirect
client.New(&Option{
    CheckRedirect: client.NoCheckRedirect,
})

Cookies

cookies, err := client.GetCookies("httpbin.org")
cookie, err := client.GetCookie("httpbin.org", "cookiename").

err := client.SetCookies("httpbin.org", cookies)
err := client.SetCookie("httpbin.org", cookie)

err := client.DelCookie("httpbin.org", "cookiename")

Debug

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

TODO

List here #1

Core symbols most depended-on inside this repo

Qs
called by 18
rq.go
New
called by 16
client/client.go
Send
called by 14
client/send.go
Set
called by 10
rq.go
Send
called by 8
rq.go
New
called by 6
rq.go
GetCookies
called by 6
client/cookie.go
ParseRequest
called by 5
request.go

Shape

Function 57
Method 18
Struct 3

Languages

Go100%

Modules by API surface

rq.go15 symbols
rq_test.go11 symbols
client/cookie_test.go8 symbols
client/client_test.go7 symbols
client/cookie.go5 symbols
request_test.go4 symbols
client/transport_test.go4 symbols
client/send_test.go4 symbols
client/client.go4 symbols
json_test.go3 symbols
client/redirect_test.go3 symbols
json.go2 symbols

For agents

$ claude mcp add rq \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact