/
methods.go
70 lines (53 loc) · 1.41 KB
/
methods.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
60
61
62
63
64
65
66
67
68
69
70
package abstract_client
import (
"github.com/go-resty/resty/v2"
)
// Get makes a GET request to the API
func (a *AbstractServiceClient) Get(path string) (*resty.Response, error) {
url := a.GetURLWithPath(path)
res, err := a.FormatRequest().Get(url)
if err != nil {
return nil, err
}
return res, nil
}
// Post makes a POST request to the API
func (a *AbstractServiceClient) Post(path string, body []byte) (*resty.Response, error) {
url := a.GetURLWithPath(path)
req := a.FormatRequest()
if body != nil {
req = req.SetBody(body)
}
res, err := req.Post(url)
if err != nil {
return nil, err
}
return res, nil
}
// Patch makes a PATCH request to the API
func (a *AbstractServiceClient) Patch(path string, body []byte) (*resty.Response, error) {
url := a.GetURLWithPath(path)
res, err := a.FormatRequest().SetBody(body).Patch(url)
if err != nil {
return nil, err
}
return res, nil
}
// Put makes a PUT request to the API
func (a *AbstractServiceClient) Put(path string, body []byte) (*resty.Response, error) {
url := a.GetURLWithPath(path)
res, err := a.FormatRequest().SetBody(body).Put(url)
if err != nil {
return nil, err
}
return res, nil
}
// Delete makes a DELETE request to the API
func (a *AbstractServiceClient) Delete(path string) (*resty.Response, error) {
url := a.GetURLWithPath(path)
res, err := a.FormatRequest().Delete(url)
if err != nil {
return nil, err
}
return res, nil
}