A Go HTTP client library with a fluent Builder pattern.
go get github.com/Li-giegie/yetiimport "github.com/Li-giegie/yeti"
// Create client
c := yeti.NewClient()
// Send GET request
var result MyStruct
c.Get().
SetUrl("https://api.example.com/users").
AddPath("123").
AddQuery("fields", "name,email").
DoResponse(ctx).
JSON(&result)Main entry point, created via NewClient().
c := yeti.NewClient()Supports hook methods to intercept requests/responses:
AddBeforeRequest(fn)- Modify Requester before building requestAddAfterRequest(fn)- Modify*http.Requestbefore sendingAddAfterResponse(fn)- Process response before returning
Obtained via yeti.R() or shortcut methods (Get(), Post(), Put(), Patch(), Delete(), etc.).
Builder methods:
| Method | Description |
|---|---|
SetMethod(method) |
Set HTTP method |
SetUrl(url) |
Set request URL |
AddPath(segment) |
Add URL path segment (auto handles slashes) |
AddQuery(key, value) |
Set query parameter |
AddQueryAny(key, value) |
Add query parameter with auto type conversion |
SetHeader(key, value) |
Set header (overwrite) |
AddHeader(key, value) |
Add header (appendable) |
SetHeaderAny(key, value) |
Set header with auto type conversion |
AddHeaderAny(key, value) |
Add header with auto type conversion |
Request body methods:
| Method | Content-Type |
|---|---|
SetBodyJSON(v) |
application/json |
SetBodyXML(v) |
application/xml |
SetBodyForm(url.Values) |
application/x-www-form-urlencoded |
SetBodyMultipartForm(map) |
multipart/form-data |
SetBodyText(string) |
text/plain |
SetBodyBinary(io.Reader) |
application/octet-stream |
Returned by DoResponse(), provides response handling:
| Method | Description |
|---|---|
EqStatusCode(code) |
Assert status code |
JSON(v) |
Parse JSON into struct |
XML(v) |
Parse XML into struct |
Validate(fn) |
Custom validation |
Enable debug logging via context:
ctx := context.WithValue(context.TODO(), yeti.ANNE_DEBUG, true)
// Or enable separately
ctx := context.WithValue(context.TODO(), yeti.ANNE_REQUEST_DEBUG, true)
ctx := context.WithValue(context.TODO(), yeti.ANNE_RESPONSE_DEBUG, true)
// Use DoDebug() shorthand
resp, err := requester.DoDebug(ctx)// GET request
c.Get().
SetUrl("https://api.example.com").
AddPath("users").
AddQuery("page", 1).
DoResponse(ctx)
// POST JSON
c.Post().
SetUrl("https://api.example.com/users").
SetBodyJSON(User{Name: "Alice", Email: "alice@example.com"}).
DoResponse(ctx)
// File upload
c.Post().
SetUrl("https://api.example.com/upload").
SetBodyMultipartForm(map[string]any{
"name": "my-file",
"file": os.Open("test.png"),
}).
DoResponse(ctx)c := yeti.NewClient()
c.Client = &http.Client{Timeout: 10 * time.Second}c := yeti.NewClient()
// Add auth header before request
c.AddBeforeRequest(func(r *yeti.Requester) error {
r.SetHeader("Authorization", "Bearer token")
return nil
})
// Log response after response
c.AddAfterResponse(func(resp *http.Response) error {
log.Printf("Response: %s", resp.Status)
return nil
})go build ./... # Build all packages
go test ./... # Run all tests
go test -v ./... # Verbose output