http2curl

package module
v0.0.0-...-1c29be0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 27, 2015 License: MIT Imports: 6 Imported by: 0

README

http2curl

📐 Convert Golang's http.Request to CURL command line

GoDoc

Example

import "github.com/moul/http2curl"

req, _ := http.NewRequest("PUT", "http://www.example.com/abc/def.ghi?jlk=mno&pqr=stu", bytes.NewBufferString(`{"hello":"world","answer":42}`))
req.Header.Set("Content-Type", "application/json")

command, _ := GetCurlCommand(req)
fmt.Println(command)
// Output: curl -X PUT -d "{\"hello\":\"world\",\"answer\":42}" -H "Content-Type: application/json" http://www.example.com/abc/def.ghi?jlk=mno&pqr=stu

Install

$ go get github.com/moul/http2curl

License

MIT

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CurlCommand

type CurlCommand struct {
	// contains filtered or unexported fields
}

CurlCommand contains exec.Command compatible slice + helpers

func GetCurlCommand

func GetCurlCommand(req *http.Request) (*CurlCommand, error)

GetCurlCommand returns a CurlCommand corresponding to an http.Request

Example
req, _ := http.NewRequest("PUT", "http://www.example.com/abc/def.ghi?jlk=mno&pqr=stu", bytes.NewBufferString(`{"hello":"world","answer":42}`))
req.Header.Set("Content-Type", "application/json")

command, _ := GetCurlCommand(req)
fmt.Println(command)
Output:

curl -X PUT -d "{\"hello\":\"world\",\"answer\":42}" -H "Content-Type: application/json" http://www.example.com/abc/def.ghi?jlk=mno&pqr=stu

func (*CurlCommand) String

func (c *CurlCommand) String() string

String returns a ready to copy/paste command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL