Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
290a1fe
Added doc for DoNotClearSuperAgent
empijei Oct 1, 2017
a4fdb89
Merge pull request #161 from empijei/develop
parnurzeal Oct 8, 2017
95984de
Don't infer header when set explicitly
harsimranmaan Oct 9, 2017
faf2e78
Remove minitests as they don't work with <go1.7
harsimranmaan Oct 9, 2017
219b5e0
Merge pull request #165 from harsimranmaan/infer_header
parnurzeal Oct 10, 2017
2221d42
updating some of the English
plod Oct 12, 2017
8e3aed2
Merge pull request #169 from plod/patch-1
parnurzeal Oct 15, 2017
2e903cc
Merge remote-tracking branch 'parnurzeal/develop' into develop-clone
fromkeith Feb 1, 2018
a9863ae
Handle error in byte stream (failed transfer of a chunk)
pkopac Oct 31, 2017
9433d8c
Merge pull request #210 from chartmogul/develop
Nov 8, 2018
b060445
Merge pull request #162 from fromkeith/develop-clone
Jan 14, 2019
6b756c0
add context support
Apr 30, 2019
30b80a8
chore: bump moul.io/http2curl dependency
moul Sep 25, 2019
b735e50
Merge pull request #234 from moul/dev/moul/bump-http2curl
QuentinPerez Sep 25, 2019
9eb6ba7
please do not ToLower
duguying Dec 26, 2019
593ff29
Add possibility to use fieldname file (not change it to file1, file2,…
macharmi Sep 16, 2020
d969c2d
Add a new spec and fix logic
macharmi Sep 17, 2020
3a0cb37
Multipart: Add possibility to use fieldname file (#252)
pkopac Sep 18, 2020
5691731
Fix wrong example
asjdf Nov 3, 2021
e15d32a
Merge pull request #227 from xiaoniaojun/add_context_support
parnurzeal Feb 21, 2024
2f6d15e
Merge pull request #266 from asjdf/develop
parnurzeal Feb 21, 2024
6e95a5f
Fix #264 to add Go Modules
parnurzeal Feb 22, 2024
3bc1f34
Merge pull request #242 from duguying/patch-1
parnurzeal Feb 22, 2024
79b2b7d
Add docs for Set and AppendHeader in README.md, issue 159
callensm Oct 17, 2017
8057805
Upgrade to Go 1.24.3 and modernize codebase
google-labs-jules[bot] Jun 1, 2025
7c2aec6
Update http2curl to V2
guywithnose Apr 2, 2025
6e1097d
fix: Correctly handle multiple Host headers
google-labs-jules[bot] Dec 4, 2025
c915942
feat: Upgrade Go version to 1.25.5
google-labs-jules[bot] Dec 4, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ GoRequest -- Simplified HTTP client ( inspired by famous SuperAgent lib in Node.

#### "Shooting Requests like a Machine Gun" - Gopher

Sending request would never been fun and easier than this. It comes with lots of feature:
Sending request has never been as fun nor easier than this. It comes with lots of features:

* Get/Post/Put/Head/Delete/Patch/Options
* Set - simple header setting
Expand Down Expand Up @@ -59,7 +59,7 @@ Or below if you don't want to reuse it for other requests.
resp, body, errs := gorequest.New().Get("http://example.com/").End()
```

How about getting control over HTTP client headers, redirect policy, and etc. Things is getting more complicated in golang. You need to create a Client, setting header in different command, ... to do just only one __GET__
How about getting control over HTTP client headers, redirect policy, and etc. Things can quickly get more complicated in golang. You need to create a Client, set headers in a different command, ... just to do only one __GET__

```go
client := &http.Client{
Expand All @@ -72,7 +72,7 @@ req.Header.Add("If-None-Match", `W/"wyzzy"`)
resp, err := client.Do(req)
```

Why making things ugly while you can just do as follows:
Why make things ugly while you can just do it as follows:

```go
request := gorequest.New()
Expand All @@ -82,7 +82,7 @@ resp, body, errs := request.Get("http://example.com").
End()
```

__DELETE__, __HEAD__, __POST__, __PUT__, __PATCH__ are now supported and can be used the same way as __GET__:
__DELETE__, __HEAD__, __POST__, __PUT__, __PATCH__ are now supported and can be used in the same way as __GET__:

```go
request := gorequest.New()
Expand All @@ -95,7 +95,7 @@ resp, body, errs := request.Post("http://example.com").End()

### JSON

For a __JSON POST__ with standard libraries, you might need to marshal map data structure to json format, setting header to 'application/json' (and other headers if you need to) and declare http.Client. So, you code become longer and hard to maintain:
For a __JSON POST__ with standard libraries, you might need to marshal map data structure to json format, set headers to 'application/json' (and other headers if you need to) and declare http.Client. So, your code becomes longer and harder to maintain:

```go
m := map[string]interface{}{
Expand Down Expand Up @@ -176,6 +176,31 @@ gorequest.New().Post("http://example.com/").

Check the docs for `SendFile` to get more information about the types of arguments.

## Headers

When setting one header to the request, the `Set` method can be used:

```go
gorequest.New().
Post("/gamelist").
Set("Accept", "application/json").
End()
```

This will clear all headers currently attached to a request and add the specified header.

If there are multiple headers that must be appended to the request before sending, use `AppendHeader`. These can be chained together to add additional headers to the request:

```go
gorequest.New().
Post("/gamelist").
AppendHeader("Accept", "application/json").
AppendHeader("Accept", "text/plain").
End()
```

See the docs for the `Set` and `AppendHeader` methods for information about parameter and return types.

## Proxy

In the case when you are behind proxy, GoRequest can handle it easily with Proxy func:
Expand Down
10 changes: 10 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module github.com/parnurzeal/gorequest

go 1.25.5

require (
github.com/elazarl/goproxy v0.0.0-20231117061959-7cc037d33fb5
github.com/pkg/errors v0.9.1
golang.org/x/net v0.21.0
moul.io/http2curl/v2 v2.3.0
)
42 changes: 42 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/elazarl/goproxy v0.0.0-20231117061959-7cc037d33fb5 h1:m62nsMU279qRD9PQSWD1l66kmkXzuYcnVJqL4XLeV2M=
github.com/elazarl/goproxy v0.0.0-20231117061959-7cc037d33fb5/go.mod h1:Ro8st/ElPeALwNFlcTpWmkr6IoMFfkjXAvTHpevnDsM=
github.com/elazarl/goproxy/ext v0.0.0-20190711103511-473e67f1d7d2 h1:dWB6v3RcOy03t/bUadywsbyrQwCqZeNIEX6M1OtSZOM=
github.com/elazarl/goproxy/ext v0.0.0-20190711103511-473e67f1d7d2/go.mod h1:gNh8nYJoAm43RfaxurUnxr+N1PwuFV3ZMl/efxlIlY8=
github.com/pkg/diff v0.0.0-20200914180035-5b29258ca4f7/go.mod h1:zO8QMzTeZd5cpnIkz/Gn6iK0jDfGicM1nynOkkPIl28=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-charset v0.0.0-20180617210344-2471d30d28b4/go.mod h1:qgYeAmZ5ZIpBWTGllZSQnw97Dj+woV0toclVaRGI8pc=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/tailscale/depaware v0.0.0-20210622194025-720c4b409502/go.mod h1:p9lPsd+cx33L3H9nNoecRRxPssFKUwwI50I3pZ0yT+8=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20201211185031-d93e913c1a58/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
moul.io/http2curl/v2 v2.3.0 h1:9r3JfDzWPcbIklMOs2TnIFzDYvfAZvjeavG6EzP7jYs=
moul.io/http2curl/v2 v2.3.0/go.mod h1:RW4hyBjTWSYDOxapodpNEtX0g5Eb16sxklBqmd2RHcE=
Loading