MCPcopy Create free account
hub / github.com/algolia/cli / request

Method request

api/crawler/client.go:45–91  ·  view source on GitHub ↗

Request sends an HTTP request and returns an HTTP response. It unmarshals the response body to the given interface.

(
	res interface{},
	method string,
	path string,
	body interface{},
	urlParams map[string]string,
)

Source from the content-addressed store, hash-verified

43// Request sends an HTTP request and returns an HTTP response.
44// It unmarshals the response body to the given interface.
45func (c *Client) request(
46 res interface{},
47 method string,
48 path string,
49 body interface{},
50 urlParams map[string]string,
51) error {
52 r, err := c.buildRequest(method, path, body, urlParams)
53 if err != nil {
54 return err
55 }
56
57 resp, err := c.client.Do(r)
58 if err != nil {
59 return err
60 }
61
62 if resp.StatusCode >= 400 {
63 var errResp ErrResponse
64 if err := unmarshalTo(resp, &errResp); err != nil {
65 return err
66 }
67
68 if errResp.Err.Errors != nil {
69 var errs []string
70 for _, e := range errResp.Err.Errors {
71 errs = append(errs, e.Message)
72 }
73 return fmt.Errorf("[%s] %s", errResp.Err.Code, errs)
74 }
75
76 // Message might be empty
77 if errResp.Err.Message == "" {
78 return errors.New(errResp.Err.Code)
79 } else {
80 return fmt.Errorf("[%s] %s", errResp.Err.Code, errResp.Err.Message)
81 }
82 }
83
84 if res != nil {
85 if err := unmarshalTo(resp, res); err != nil {
86 return err
87 }
88 }
89
90 return nil
91}
92
93// buildRequestWithoutBody builds an HTTP request without a body.
94func (c *Client) buildRequestWithoutBody(method, url string) (*http.Request, error) {

Callers 10

CreateMethod · 0.95
ListMethod · 0.95
GetMethod · 0.95
RunMethod · 0.95
PauseMethod · 0.95
ReindexMethod · 0.95
StatsMethod · 0.95
CrawlURLsMethod · 0.95
TestMethod · 0.95
CancelTaskMethod · 0.95

Calls 3

buildRequestMethod · 0.95
unmarshalToFunction · 0.85
ErrorfMethod · 0.65

Tested by

no test coverage detected