All Projects → ddo → rq

ddo / rq

Licence: Apache-2.0 License
A nicer interface for golang stdlib HTTP client

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to rq

axios-case-converter
Axios transformer/interceptor that converts snake_case/camelCase
Stars: ✭ 114 (+185%)
Mutual labels:  http-client
heroshi
Heroshi – open source web crawler.
Stars: ✭ 51 (+27.5%)
Mutual labels:  http-client
RESTEasy
REST API calls made easier
Stars: ✭ 12 (-70%)
Mutual labels:  http-client
malloy
A C++ library providing embeddable server & client components for both HTTP and WebSocket.
Stars: ✭ 29 (-27.5%)
Mutual labels:  http-client
foxy
Session-based Beast/Asio wrapper requiring C++14
Stars: ✭ 61 (+52.5%)
Mutual labels:  http-client
ivar
Ivar is an adapter based HTTP client that provides the ability to build composable HTTP requests.
Stars: ✭ 14 (-65%)
Mutual labels:  http-client
hunt-http
http library for D, support http 1.1 / http 2.0 (http2) / websocket server and client.
Stars: ✭ 29 (-27.5%)
Mutual labels:  http-client
SimplecURL
Easy to use HTTP Client for PHP
Stars: ✭ 14 (-65%)
Mutual labels:  http-client
libashttp
A C++ async HTTP client library to use in asynchronous applications while communicating with REST services.
Stars: ✭ 51 (+27.5%)
Mutual labels:  http-client
Rester
A command line tool to test (REST) APIs
Stars: ✭ 42 (+5%)
Mutual labels:  http-client
java-restify
Java Restify - Simple interface-based HTTP client for Java
Stars: ✭ 31 (-22.5%)
Mutual labels:  http-client
clj-http-hystrix
A Clojure library to wrap clj-http requests as hystrix commands
Stars: ✭ 21 (-47.5%)
Mutual labels:  http-client
chclient
Fast http client for SELECT queries in clickhouse
Stars: ✭ 44 (+10%)
Mutual labels:  http-client
watermelon-http-client
GitHub Action to perform HTTP requests. Supports GraphQL!
Stars: ✭ 21 (-47.5%)
Mutual labels:  http-client
desktop
A native GUI application that makes it easy to explore and test Serverless Framework applications built on AWS Lambda.
Stars: ✭ 42 (+5%)
Mutual labels:  http-client
domhttpx
domhttpx is a google search engine dorker with HTTP toolkit built with python, can make it easier for you to find many URLs/IPs at once with fast time.
Stars: ✭ 59 (+47.5%)
Mutual labels:  http-client
centra
Core Node.js HTTP client
Stars: ✭ 52 (+30%)
Mutual labels:  http-client
ELWebService
A lightweight HTTP networking framework for Swift
Stars: ✭ 89 (+122.5%)
Mutual labels:  http-client
lhc
🚀 Advanced HTTP Client for Ruby. Fueled with interceptors.
Stars: ✭ 32 (-20%)
Mutual labels:  http-client
curly.hpp
Simple cURL C++17 wrapper
Stars: ✭ 48 (+20%)
Mutual labels:  http-client

rq Build Status Go Report codecov

A nicer interface for golang stdlib HTTP client

Documents

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
  • Better cookie jar
  • Import/export allow we save/transfer requests in JSON
  • Default setting: example default User-Agent or Accept-Language

Installation

go get -u github.com/ddo/rq

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
// no cookie jar
// and stops after 10 consecutive requests (10 redirects)
customClient := client.New(nil)

Custom Options

import "github.com/ddo/rq/client/jar"

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", "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 Doc

import "github.com/ddo/rq/client/jar"

cookieJar := jar.New()

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

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

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

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

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

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

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

Debug

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

TODO

List here #1

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].