Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(curl): generate curl cmd for request && example for curl cmd #794

Open
wants to merge 2 commits into
base: v2
Choose a base branch
from

Conversation

ahuigo
Copy link

@ahuigo ahuigo commented May 11, 2024

I've extracted curl code from my previous PR(#734).
Could you review this code?

New feature: generate curl command

Example: https://github.com/ahuigo/resty/blob/curl/v2/examples/debug_curl_test.go

var curlCmdExecuted string
client := resty.New()
_, err := client.R().
    SetResultCurlCmd(&curlCmdExecuted).
    Get("https://httpbin.org/get")

// Explore curl command
fmt.Println("Curl Command:", curlCmdExecuted)

Output

$ go test -run '^TestDebugCurl$' github.com/go-resty/resty/v2/examples -v
=== RUN   TestDebugCurl
    debug_curl_test.go:29: curlCmdUnexecuted:  
    curl -X GET -H 'Content-Type: application/json' -H 'Cookie: count=1' -H 'User-Agent: go-resty/2.12.0 (https://github.com/go-resty/resty)' -d '{"name":"Alex"}' 'http://unexecuted-url'

    debug_curl_test.go:41: curlCmdExecuted:  
    curl -X POST -H 'Accept: application/json' -H 'Content-Type: application/json' -H 'Cookie: count=1; count=1' -H 'User-Agent: go-resty/2.12.0 (https://github.com/go-resty/resty)' -d '{"name":"Alex"}' http://127.0.0.1:56426/post
--- PASS: TestDebugCurl (0.00s)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant