Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/monaco-io/request
go request, go http client
https://github.com/monaco-io/request
axios client go golang gorequest http net request
Last synced: about 2 months ago
JSON representation
go request, go http client
- Host: GitHub
- URL: https://github.com/monaco-io/request
- Owner: monaco-io
- License: mit
- Created: 2020-03-25T06:24:18.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-01-10T10:24:46.000Z (11 months ago)
- Last Synced: 2024-07-31T20:52:37.321Z (4 months ago)
- Topics: axios, client, go, golang, gorequest, http, net, request
- Language: Go
- Homepage: https://pkg.go.dev/github.com/monaco-io/request?tab=doc
- Size: 104 KB
- Stars: 289
- Watchers: 11
- Forks: 29
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
- awesome-go - request - HTTP client for golang. If you have experience about axios or requests, you will love it. No 3rd dependency. (Networking / HTTP Clients)
- zero-alloc-awesome-go - request - HTTP client for golang. If you have experience about axios or requests, you will love it. No 3rd dependency. (Networking / HTTP Clients)
- awesome-go-extra - request - 03-25T06:24:18Z|2021-12-28T03:28:07Z| (Networking / HTTP Clients)
README
# Request [![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go) [![Go Report Card](https://goreportcard.com/badge/github.com/monaco-io/request)](https://goreportcard.com/report/github.com/monaco-io/request) ![Go](https://github.com/monaco-io/request/workflows/Go/badge.svg)
[![GoDoc](https://godoc.org/github.com/monaco-io/request?status.svg)](https://pkg.go.dev/github.com/monaco-io/request?tab=doc)
[![codecov](https://codecov.io/gh/monaco-io/request/branch/master/graph/badge.svg)](https://codecov.io/gh/monaco-io/request)
[![Release](https://img.shields.io/github/release/monaco-io/request.svg?style=flat-square)](https://github.com/monaco-io/request/releases)
[![TODOs](https://badgen.net/https/api.tickgit.com/badgen/github.com/monaco-io/request)](https://www.tickgit.com/browse?repo=github.com/monaco-io/request)
[![License](https://img.shields.io/github/license/monaco-io/request?style=plastic)](https://github.com/monaco-io/request/blob/master/LICENSE)HTTP Client for golang, Inspired by [Javascript-axios](https://github.com/axios/axios) [Python-request](https://github.com/psf/requests).
If you have experience about axios or requests, you will love it.
No 3rd dependency.## Features
- Make [http](https://golang.org) requests from Golang
- Transform request and response data## Installing
go mod:
```bash
go get github.com/monaco-io/request
```## Methods
- OPTIONS
- GET
- HEAD
- POST
- PUT
- DELETE
- TRACE
- CONNECT## Example
### POST
```go
package mainimport (
"github.com/monaco-io/request"
)func main() {
var body = struct {
A string
B int
}{A: "A", B: 1}
var result interface{}c := request.Client{
URL: "https://google.com",
Method: "POST",
Query: map[string]string{"hello": "world"},
JSON: body,
}
resp := c.Send().Scan(&result)
if !resp.OK(){
// handle error
log.Println(resp.Error())
}// str := resp.String()
// bytes := resp.Bytes()
```### POST with local files
```go
package mainimport (
"github.com/monaco-io/request"
)func main() {
c := request.Client{
URL: "https://google.com",
Method: "POST",
Query: map[string]string{"hello": "world"},
MultipartForm: MultipartForm{
Fields: map[string]string{"a": "1"},
Files: []string{"doc.txt"},
},
}
resp := c.Send().Scan(&result)
...
```### POST step by step
```go
package mainimport (
"github.com/monaco-io/request"
)func main() {
var response 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(&response)
...
```### POST with context (1/2)
```go
package mainimport (
"github.com/monaco-io/request"
"context"
)func main() {
c := request.Client{
Context: context.Background(),
URL: "https://google.com",
Method: "POST",
BasicAuth: request.BasicAuth{
Username: "google",
Password: "google",
},
}
resp := c.Send()
...
```### POST with context (2/2)
```go
package mainimport (
"github.com/monaco-io/request"
"context"
)func main() {
var response interface{}resp := request.
NewWithContext(context.TODO()).
POST("http://httpbin.org/post").
AddHeader(map[string]string{"Google": "google"}).
AddBasicAuth("google", "google").
AddURLEncodedForm(map[string]string{"data": "google"}).
Send().
Scan(&response)
...
```### Authorization
```go
package mainimport (
"github.com/monaco-io/request"
)func main() {
c := request.Client{
URL: "https://google.com",
Method: "POST",
BasicAuth: request.BasicAuth{
Username: "google",
Password: "google",
},
}
resp := c.Send()
}
```### Timeout
```go
package mainimport (
"github.com/monaco-io/request"
)func main() {
c := request.Client{
URL: "https://google.com",
Method: "POST",
Timeout: time.Second*10,
}
}
```### Cookies
```go
package mainimport (
"github.com/monaco-io/request"
)func main() {
c := request.Client{
URL: "https://google.com",
CookiesMap: map[string]string{
"cookie_name": "cookie_value",
}
}
}
```### TLS
```go
package mainimport (
"github.com/monaco-io/request"
)func main() {
c := request.Client{
URL: "https://google.com",
TLSConfig: &tls.Config{InsecureSkipVerify: true},
}
}
```## License
[MIT](LICENSE)