Skip to content
This repository has been archived by the owner on Jul 14, 2022. It is now read-only.

Commit

Permalink
🌱Added PATCH method
Browse files Browse the repository at this point in the history
  • Loading branch information
athul committed Jan 25, 2020
1 parent a82e580 commit 304e2fa
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ func main() {
return nil
},
},
{
Name: "patch",
Usage: "Send a PATCH Request",
Flags: postFlags,
Action: func(c *cli.Context) error {
mets.Patchbasic(c)
return nil
},
},
}
err := app.Run(os.Args)
if err != nil {
Expand Down
35 changes: 35 additions & 0 deletions methods/patch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package methods

import (
"bytes"
"fmt"
"net/http"

"github.com/urfave/cli"
)

//Patchbasic sends a basic PATCH request
func Patchbasic(c *cli.Context) {
url := c.String("url")
var jsonStr = []byte(c.String("body"))
req, err := http.NewRequest("PATCH", url, bytes.NewBuffer(jsonStr))
//req.Header.Set("X-Custom-Header", "myvalue")
req.Header.Set("Content-Type", c.String("ctype"))
if c.String("token") != "" {
var bearer = "Bearer " + c.String("token")
req.Header.Add("Authorization", bearer)
}
if c.String("u") != "" && c.String("p") != "" {
un := c.String("u")
pw := c.String("p")
req.Header.Add("Authorization", "Basic "+basicAuth(un, pw))
}
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
s := formatresp(resp)
fmt.Println(s)
}

0 comments on commit 304e2fa

Please sign in to comment.