-
Notifications
You must be signed in to change notification settings - Fork 0
/
request_form.go
59 lines (52 loc) · 1.25 KB
/
request_form.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package resty
import (
"net/http"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
"github.com/saeedafzal/resty/api"
"github.com/saeedafzal/resty/helper"
)
var methods = []string{
http.MethodGet,
http.MethodPost,
http.MethodPut,
http.MethodDelete,
http.MethodHead,
http.MethodOptions,
http.MethodTrace,
http.MethodPatch,
http.MethodConnect,
}
func (r Resty) requestForm() *tview.Form {
req := r.requestData
form := tview.NewForm().
SetButtonBackgroundColor(tcell.ColorIndigo).
SetFieldBackgroundColor(tcell.ColorIndigo).
AddDropDown("Method", methods, 0, func(option string, _ int) {
req.Method = option
r.updateRequestSummary()
}).
AddInputField("URL", "", 0, nil, func(text string) {
req.Url = text
r.updateRequestSummary()
}).
AddButton("Headers", func() {
r.pages.AddAndSwitchToPage(helper.HEADER_DIALOG, r.headersDialog(), true)
}).
AddButton("Send", func() {
r.requestData.Body = r.requestBody.GetText()
res, err := api.DoRequest(r.requestData)
if err != nil {
r.updateResponseSummaryError(err)
r.responseBody.SetText("")
return
}
r.updateResponseSummary(res)
r.updateResponseBody(res)
})
form.
SetBorder(true).
SetTitle("Request Form")
r.components[0] = form
return form
}