Skip to content

Commit 05c3b1d

Browse files
committed
merger into PR#2
1 parent 902bf6e commit 05c3b1d

File tree

4 files changed

+15
-20
lines changed

4 files changed

+15
-20
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Go implemented CLI cURL-like tool for humans. Bat can be used for testing, debug
33

44
Inspired by [Httpie](https://github.com/jakubroztocil/httpie). Thanks to the author, Jakub.
55

6+
67
![](images/logo.png)
78

89

@@ -45,10 +46,14 @@ See also `bat --help`.
4546

4647
### Examples
4748

48-
Custom [HTTP method](#http-method), [HTTP headers](#http-headers) and [JSON](#json) data:
49+
Basic settings - [HTTP method](#http-method), [HTTP headers](#http-headers) and [JSON](#json) data:
4950

5051
$ bat PUT example.org X-API-Token:123 name=John
5152

53+
Any custom HTTP method (such as WebDAV, etc.):
54+
55+
$ bat -method=PROPFIND example.org name=John
56+
5257
Submitting forms:
5358

5459
$ bat -form=true POST example.org hello=World

filter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func filter(args []string) []string {
1212
if inSlice(strings.ToUpper(args[i]), methodList) {
1313
*method = strings.ToUpper(args[i])
1414
i++
15-
} else if len(args) > 0 {
15+
} else if len(args) > 0 && *method == "GET" {
1616
for _, v := range args[1:] {
1717
// defaults to either GET (with no request data) or POST (with request data).
1818
// Params

http.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,7 @@ var defaultSetting = httplib.BeegoHttpSettings{
2020
}
2121

2222
func getHTTP(method string, url string, args []string) (r *httplib.BeegoHttpRequest) {
23-
switch method {
24-
case "GET":
25-
r = httplib.Get(url)
26-
case "POST":
27-
r = httplib.Post(url)
28-
case "PUT":
29-
r = httplib.Put(url)
30-
case "HEAD":
31-
r = httplib.Head(url)
32-
case "DELETE":
33-
r = httplib.Delete(url)
34-
}
23+
r = httplib.NewBeegoRequest(url, method)
3524
r.Setting(defaultSetting)
3625
r.Header("Accept-Encoding", "gzip, deflate")
3726
if *isjson {

httplib/httplib.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Copyright 2014 beego Author. All Rights Reserved.
2+
// Copyright 2015 bat authors
23
//
34
// Licensed under the Apache License, Version 2.0 (the "License");
45
// you may not use this file except in compliance with the License.
@@ -76,7 +77,7 @@ func SetDefaultSetting(setting BeegoHttpSettings) {
7677
}
7778

7879
// return *BeegoHttpRequest with specific method
79-
func newBeegoRequest(url, method string) *BeegoHttpRequest {
80+
func NewBeegoRequest(url, method string) *BeegoHttpRequest {
8081
var resp http.Response
8182
req := http.Request{
8283
Method: method,
@@ -90,27 +91,27 @@ func newBeegoRequest(url, method string) *BeegoHttpRequest {
9091

9192
// Get returns *BeegoHttpRequest with GET method.
9293
func Get(url string) *BeegoHttpRequest {
93-
return newBeegoRequest(url, "GET")
94+
return NewBeegoRequest(url, "GET")
9495
}
9596

9697
// Post returns *BeegoHttpRequest with POST method.
9798
func Post(url string) *BeegoHttpRequest {
98-
return newBeegoRequest(url, "POST")
99+
return NewBeegoRequest(url, "POST")
99100
}
100101

101102
// Put returns *BeegoHttpRequest with PUT method.
102103
func Put(url string) *BeegoHttpRequest {
103-
return newBeegoRequest(url, "PUT")
104+
return NewBeegoRequest(url, "PUT")
104105
}
105106

106107
// Delete returns *BeegoHttpRequest DELETE method.
107108
func Delete(url string) *BeegoHttpRequest {
108-
return newBeegoRequest(url, "DELETE")
109+
return NewBeegoRequest(url, "DELETE")
109110
}
110111

111112
// Head returns *BeegoHttpRequest with HEAD method.
112113
func Head(url string) *BeegoHttpRequest {
113-
return newBeegoRequest(url, "HEAD")
114+
return NewBeegoRequest(url, "HEAD")
114115
}
115116

116117
// BeegoHttpSettings

0 commit comments

Comments
 (0)