Skip to content

msoedov/coorl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Coorl

Translates net/http to a coooool curl command for debugging and troubleshooting

Getting Started

Example

url := "http://restapi3.apiary.io/notes"
jsonStr := []byte(`{"title":"Buy cheese and bread for breakfast."}`)
b := bytes.NewReader(jsonStr)
req, err := http.NewRequest("POST", url, b)
req.Header.Set("X-Custom-Header", "myvalue")
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
_, err = client.Do(req)
if err != nil {
    panic(err)
}

fmt.Printf("%s\n", coorl.AsCurl(req, b))

Output

curl -v  --request POST -H 'X-Custom-Header: myvalue' -H 'Content-Type: application/json' --data '{\"title\":\"Buy cheese and bread for breakfast.\"}' http://restapi3.apiary.io/notes

Translate to httpie

fmt.Printf("%s\n", coorl.AsHttpie(req, b))
echo '{\"title\":\"Buy cheese and bread for breakfast.\"}' | http -v POST http://restapi3.apiary.io/notes X-Custom-Header:myvalue Content-Type:application/json

Prerequisites

package coorl // import "github.com/msoedov/coorl"

func AsCurl(r *http.Request, body io.ReadSeeker) (cmd string)
func AsHttpie(r *http.Request, body io.ReadSeeker) (cmd string)

Installing

A step by step series of examples that tell you have to get a development env running

go get -u github.com/msoedov/coorl

Running the tests

go test

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

About

A coooool curl command from net/http

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages