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

Method buildRequest

api/crawler/client.go:114–138  ·  view source on GitHub ↗

buildRequest builds an HTTP request.

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

Source from the content-addressed store, hash-verified

112
113// buildRequest builds an HTTP request.
114func (c *Client) buildRequest(
115 method, path string,
116 body interface{},
117 urlParams map[string]string,
118) (req *http.Request, err error) {
119 url := DefaultBaseURL + path
120
121 if body == nil {
122 req, err = c.buildRequestWithoutBody(method, url)
123 } else {
124 req, err = c.buildRequestWithBody(method, url, body)
125 }
126
127 req.SetBasicAuth(c.UserID, c.APIKey)
128 req.Header.Set("Content-Type", "application/json")
129
130 // Add URL params
131 values := req.URL.Query()
132 for k, v := range urlParams {
133 values.Set(k, v)
134 }
135 req.URL.RawQuery = values.Encode()
136
137 return req, err
138}
139
140// unmarshalTo unmarshals an HTTP response body to a given interface.
141func unmarshalTo(r *http.Response, v interface{}) error {

Callers 1

requestMethod · 0.95

Calls 3

buildRequestWithBodyMethod · 0.95
SetMethod · 0.45

Tested by

no test coverage detected