https://github.com/prongbang/callx
CallX HTTP Client easy call API for Golang
https://github.com/prongbang/callx
callx go go-callx go-http-client golang http http-client
Last synced: 7 months ago
JSON representation
CallX HTTP Client easy call API for Golang
- Host: GitHub
- URL: https://github.com/prongbang/callx
- Owner: prongbang
- License: mit
- Created: 2020-06-27T17:58:39.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-09-19T16:36:00.000Z (about 1 year ago)
- Last Synced: 2025-03-07T20:18:48.579Z (7 months ago)
- Topics: callx, go, go-callx, go-http-client, golang, http, http-client
- Language: Go
- Homepage:
- Size: 32.2 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CallX
CallX HTTP Client easy call API for Golang
[](https://travis-ci.org/prongbang/callx)
[](https://codecov.io/gh/prongbang/callx)
[](https://goreportcard.com/report/github.com/prongbang/callx)[](https://www.buymeacoffee.com/prongbang)
### Install
```
go get github.com/prongbang/callx
```### Benchmark
```shell
Benchmark_CallXRequests/GET-10 41756 31823 ns/op
Benchmark_CallXRequests/POST-10 38692 35787 ns/op
Benchmark_CallXRequests/POST-ENCODE-10 28848 39314 ns/op
Benchmark_CallXRequests/PUT-10 31401 35046 ns/op
Benchmark_CallXRequests/PATCH-10 38923 30094 ns/op
Benchmark_CallXRequests/DELETE-10 41100 29195 ns/op
```### How to use
- Using base URL
```golang
c := callx.Config{
BaseURL: "https://jsonplaceholder.typicode.com",
Timeout: 60,
}
req := callx.New(c)data := req.Get("/todos/1")
fmt.Println(string(data.Data))
```- Custom request
```golang
c := callx.Config{
Timeout: 60,
}
req := callx.New(c)custom := callx.Custom{
URL: "https://httpbin.org/post",
Method: http.MethodPost,
Header: callx.Header{
callx.Authorization: fmt.Sprintf("%s %s", callx.Bearer, "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.Et9HFtf9R3GEMA0IICOfFMVXY7kkTX1wr4qCyhIf58U"),
},
Body: callx.Body{
"username": "root",
"password": "pass",
"address": []string{
"087654321",
"089786756",
},
},
}
data := req.Req(custom)
fmt.Println(string(data.Data))
```- Custom request form encoded
```golang
c := callx.Config{
Timeout: 60,
}
req := callx.New(c)form := url.Values{}
form.Set("message", "Test")custom := callx.Custom{
URL: "https://httpbin.org/post",
Method: http.MethodPost,
Header: callx.Header{
callx.Authorization: "Bearer XTZ",
callx.ContentType: "application/x-www-form-urlencoded",
},
Form: strings.NewReader(form.Encode()),
}
data := req.Req(custom)
fmt.Println(string(data.Data))
```