// 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) }