All checks were successful
CI / test (push) Successful in 31s
Six examples covering the full API surface: - basic-client: retry, timeout, logging, response size limit - form-request: form-encoded POST for OAuth/webhooks - load-balancing: weighted endpoints, circuit breaker, health checks - server-basic: routing, groups, JSON helpers, health, custom 404 - server-protected: CORS, rate limiting, body limits, timeouts - request-id-propagation: cross-service request ID forwarding Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
42 lines
818 B
Go
42 lines
818 B
Go
// Demonstrates form-encoded requests for OAuth token endpoints and similar APIs.
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log"
|
|
"net/http"
|
|
"net/url"
|
|
|
|
"git.codelab.vc/pkg/httpx"
|
|
)
|
|
|
|
func main() {
|
|
client := httpx.New(
|
|
httpx.WithBaseURL("https://httpbin.org"),
|
|
)
|
|
defer client.Close()
|
|
|
|
ctx := context.Background()
|
|
|
|
// Form-encoded POST, common for OAuth token endpoints.
|
|
req, err := httpx.NewFormRequest(ctx, http.MethodPost, "/post", url.Values{
|
|
"grant_type": {"client_credentials"},
|
|
"client_id": {"my-app"},
|
|
"client_secret": {"secret"},
|
|
"scope": {"read write"},
|
|
})
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
resp, err := client.Do(ctx, req)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
defer resp.Close()
|
|
|
|
body, _ := resp.String()
|
|
fmt.Printf("Status: %d\nBody: %s\n", resp.StatusCode, body)
|
|
}
|