https://github.com/subchen/go-curl
A Go HTTP client library for creating and sending API requests
https://github.com/subchen/go-curl
curl golang http request rest-api
Last synced: 7 days ago
JSON representation
A Go HTTP client library for creating and sending API requests
- Host: GitHub
- URL: https://github.com/subchen/go-curl
- Owner: subchen
- License: apache-2.0
- Created: 2018-02-09T13:02:42.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-03-15T15:48:38.000Z (almost 8 years ago)
- Last Synced: 2024-06-20T05:08:11.467Z (over 1 year ago)
- Topics: curl, golang, http, request, rest-api
- Language: Go
- Size: 105 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-curl
[](https://goreportcard.com/report/github.com/subchen/go-curl)
[](https://godoc.org/github.com/subchen/go-curl)
A Go HTTP client library for creating and sending API requests
## Examples
```go
import "github.com/subchen/go-curl"
```
### Basic request
```go
req := curl.NewRequest(nil)
// GET
resp, err := req.Get("http://example.com/api/users")
if err != nil {
log.Fatalln("Unable to make request: ", err)
}
fmt.Println(resp.Text())
// POST
user := &User{...}
resp, err := req.Post("http://example.com/api/users", user)
if err != nil {
log.Fatalln("Unable to make request: ", err)
}
fmt.Println(resp.Text())
```
### Chained request
```go
user := newUser()
req := curl.NewRequest()
resp, err := req.WithBasicAuth("admin", "passwd").WithHeader("x-trace-id", "123").Post("http://example.com/api/users")
if err != nil {
log.Fatalln("Unable to make request: ", err)
}
fmt.Println(resp.Text())
```