http client for golang

Overview

Request Mentioned in Awesome Go Go Report Card Go

GoDoc codecov Release TODOs License

HTTP client for golang, Inspired by Javascript-axios Python-request. If you have experience about axios or requests, you will love it. No 3rd dependency.

Features

  • Make http requests from Golang
  • Transform request and response data

Installing

go mod:

go get github.com/monaco-io/request

Methods

  • OPTIONS
  • GET
  • HEAD
  • POST
  • PUT
  • DELETE
  • TRACE
  • CONNECT

Example

POST

package main

import (
    "github.com/monaco-io/request"
)

func main() {
    client := request.Client{
        URL:    "https://google.com",
        Method: "POST",
        Query: map[string]string{"hello": "world"},
        JSON:   []byte(`{"hello": "world"}`),
    }
    var result interface{}
    resp := client.Send()
    err := resp.Scan(&result).Error()
    str := resp.String()
    bytes := resp.Bytes()
    ...

POST with empty request

package main

import (
    "github.com/monaco-io/request"
)

func main() {
    var data interface{}

    resp := request.
        New().
        POST("http://httpbin.org/post").
        AddHeader(map[string]string{"Google": "google"}).
        AddBasicAuth("google", "google").
        AddURLEncodedForm(map[string]string{"data": "google"}).
        Send().
        Scan(&data)
    ...

Authorization

package main

import (
    "github.com/monaco-io/request"
)

func main() {
    client := request.Client{
        URL:       "https://google.com",
        Method:    "POST",
        BasicAuth: request.BasicAuth{
            Username:"user_xxx",
            Password:"pwd_xxx",
        },
    }
}

Timeout

package main

import (
    "github.com/monaco-io/request"
)

func main() {
    client := request.Client{
        URL:       "https://google.com",
        Method:    "POST",
        Timeout:   time.Second*10,
    }
}

Cookies

package main

import (
    "github.com/monaco-io/request"
)

func main() {
    client := request.Client{
        URL:       "https://google.com",
        CookiesMap: map[string]string{
            "cookie_name": "cookie_value",
        }
    }
}

TLS

package main

import (

    "github.com/monaco-io/request"
)

func main() {
    client := request.Client{
        URL:       "https://google.com",
        TLSConfig: &tls.Config{InsecureSkipVerify: true},
    }
}

License

MIT

Issues
  • AMAZING PROJECT I LOVE IT SO MUCH!!!!!

    AMAZING PROJECT I LOVE IT SO MUCH!!!!!

    Its the best request library right now https://gist.github.com/bgbusted/698a76a42794364238ed0eb2b91e6186

    my issue is one thing the HEADERs goes by the ABC ? how can I make it like chrome ? image

    I already got the fingerprint done but I still have issues with the headers its not as it is on chrome :)

    opened by bgbusted 9
  • Failed connection causes panic

    Failed connection causes panic

    Hello, you have great library there. I found something very unsettling. If connection doesnt happen(host down), calling sugar.Code() causes nil pointer panic because Response member is nil. Would you consider preventing that? Something like

    func (s *Sugar) Code() int {
      if s.ctx.Response == nil {
        return 0
      }
      return s.ctx.Response.StatusCode
    }
    
    opened by qwerty2586 2
  • Allowing modification of http.client

    Allowing modification of http.client

    Hey, I am trying to pass in a non default http client. Similar to something like this:

    defaultRoundTripper := http.DefaultTransport
      defaultTransportPointer, ok := defaultRoundTripper.(*http.Transport)
      if !ok {
          panic(fmt.Sprintf("defaultRoundTripper not an *http.Transport"))
      }
      defaultTransport := *defaultTransportPointer // dereference it to get a copy of the struct that the pointer points to
      defaultTransport.MaxIdleConns = 100
      defaultTransport.MaxIdleConnsPerHost = 100
    
      myClient = &http.Client{Transport: &defaultTransport}
    

    I don't see any way that is obvious but I'm open to making some minor changes, for example making it public public in the request.Client struct. Is there a way that would make sense to you and I could submit a PR?

    opened by margolisj 2
  • Move set user-agent upper

    Move set user-agent upper

    Dont work this one.

    	client2 := request.Client{
    		URL:    "https://update-api.1c.ru/update-platform/programs/update/",
    		Method: "POST",
    		Header: map[string]string{
    			"Content-Type": "application/json",
    			"User-Agent": "1C+Enterprise/8.3",
    		},
    	}
    
    

    Move setup User_Agent header upper appy headers

    opened by khorevaa 1
Releases(v1.0.15)
Speak HTTP like a local. (the simple, intuitive HTTP console, golang version)

http-gonsole This is the Go port of the http-console. Speak HTTP like a local Talking to an HTTP server with curl can be fun, but most of the time it'

mattn 65 Jul 14, 2021
NATS HTTP Round Tripper - This is a Golang http.RoundTripper that uses NATS as a transport.

This is a Golang http.RoundTripper that uses NATS as a transport. Included is a http.RoundTripper for clients, a server that uses normal HTTP Handlers and any existing http handler mux and a Caddy Server transport.

R.I.Pienaar 75 Jun 14, 2022
Http-conection - A simple example of how to establish a HTTP connection using Golang

A simple example of how to establish a HTTP connection using Golang

Jonathan Gonzaga 0 Feb 1, 2022
An enhanced http client for Golang

go-http-client An enhanced http client for Golang Documentation on go.dev ?? This package provides you a http client package for your http requests. Y

Furkan Bozdag 40 May 23, 2022
http client for golang

Request HTTP client for golang, Inspired by Javascript-axios Python-request. If you have experience about axios or requests, you will love it. No 3rd

Monaco.HappyHacking 206 Jun 24, 2022
A nicer interface for golang stdlib HTTP client

rq A nicer interface for golang stdlib HTTP client Documents rq: here client: here jar: here Why? Because golang HTTP client is a pain in the a... Fea

Ddo 40 Jan 23, 2022
Declarative golang HTTP client

go-req Declarative golang HTTP client package req_test

陈杨文 15 Apr 11, 2022
Advanced HTTP client for golang.

go-request Advanced HTTP client for golang. Installation go get github.com/mingming-cn/go-request Usage import ( "github.com/mingming-cn/go-reque

null 1 Nov 22, 2021
Fast HTTP package for Go. Tuned for high performance. Zero memory allocations in hot paths. Up to 10x faster than net/http

fasthttp Fast HTTP implementation for Go. Currently fasthttp is successfully used by VertaMedia in a production serving up to 200K rps from more than

Aliaksandr Valialkin 17.9k Jun 26, 2022
Simple HTTP package that wraps net/http

Simple HTTP package that wraps net/http

Kris 0 Jan 17, 2022
Full-featured, plugin-driven, extensible HTTP client toolkit for Go

gentleman Full-featured, plugin-driven, middleware-oriented toolkit to easily create rich, versatile and composable HTTP clients in Go. gentleman embr

Tom 957 Jun 22, 2022
An enhanced HTTP client for Go

Heimdall Description Installation Usage Making a simple GET request Creating a hystrix-like circuit breaker Creating a hystrix-like circuit breaker wi

Gojek 2.3k Jun 24, 2022
Enriches the standard go http client with retry functionality.

httpRetry Enriches the standard go http client with retry functionality using a wrapper around the Roundtripper interface. The advantage of this libra

Alexander Gehres 20 May 10, 2022
Simple HTTP and REST client library for Go

Resty Simple HTTP and REST client library for Go (inspired by Ruby rest-client) Features section describes in detail about Resty capabilities Resty Co

Go Resty 6.3k Jun 26, 2022
A Go HTTP client library for creating and sending API requests

Sling Sling is a Go HTTP client library for creating and sending API requests. Slings store HTTP Request properties to simplify sending requests and d

Dalton Hubble 1.4k Jun 19, 2022
a Go HTTP client with timeouts

go-httpclient requires Go 1.1+ as of v0.4.0 the API has been completely re-written for Go 1.1 (for a Go 1.0.x compatible release see 1adef50) Provides

Matt Reiferson 290 Sep 7, 2021
GoRequest -- Simplified HTTP client ( inspired by nodejs SuperAgent )

GoRequest GoRequest -- Simplified HTTP client ( inspired by famous SuperAgent lib in Node.js ) "Shooting Requests like a Machine Gun" - Gopher Sending

Theeraphol Wattanavekin 3.2k Jun 28, 2022
gout to become the Swiss Army Knife of the http client @^^@---> gout 是http client领域的瑞士军刀,小巧,强大,犀利。具体用法可看文档,如使用迷惑或者API用得不爽都可提issues

gout gout 是go写的http 客户端,为提高工作效率而开发 构架 feature 支持设置 GET/PUT/DELETE/PATH/HEAD/OPTIONS 支持设置请求 http header(可传 struct,map,array,slice 等类型) 支持设置 URL query(可

guonaihong 1k Jun 20, 2022
Retry, Race, All, Some, etc strategies for http.Client calls

reqstrategy Package reqstrategy provides functions for coordinating http.Client calls. It wraps typical call strategies like making simultaneous reque

Sergiy Yavorsky 11 Apr 30, 2021