https://github.com/msoedov/coorl
A coooool curl command from net/http
https://github.com/msoedov/coorl
curl golang net-http
Last synced: 3 months ago
JSON representation
A coooool curl command from net/http
- Host: GitHub
- URL: https://github.com/msoedov/coorl
- Owner: msoedov
- Created: 2018-02-10T01:41:34.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-02-12T22:14:10.000Z (over 7 years ago)
- Last Synced: 2025-01-14T11:17:25.167Z (5 months ago)
- Topics: curl, golang, net-http
- Language: Go
- Homepage:
- Size: 8.79 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# Coorl
Translates `net/http` to a coooool curl command for debugging and troubleshooting
## Getting Started
Example
```go
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
```bash
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`
```go
fmt.Printf("%s\n", coorl.AsHttpie(req, b))
``````shell
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
```go
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
```shell
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](LICENSE.md) file for details
## Acknowledgments