This repository has been archived by the owner on Jul 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from athul/put
Put, Patch and Delete Methods Added
- Loading branch information
Showing
8 changed files
with
147 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
) | ||
|
||
//Deletebasic sends a basic DELETE request | ||
func Deletebasic(c *cli.Context) { | ||
url := c.String("url") | ||
var jsonStr = []byte(c.String("body")) | ||
req, err := http.NewRequest("DELETE", 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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package methods | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/urfave/cli" | ||
) | ||
|
||
//Putbasic sends a basic PUT request | ||
func Putbasic(c *cli.Context) { | ||
url := c.String("url") | ||
var jsonStr = []byte(c.String("body")) | ||
req, err := http.NewRequest("PUT", 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) | ||
} |