MCPcopy Create free account
hub / github.com/exercism/cli / NewRequest

Method NewRequest

api/client.go:41–62  ·  view source on GitHub ↗

NewRequest returns an http.Request with information for the Exercism API.

(method, url string, body io.Reader)

Source from the content-addressed store, hash-verified

39
40// NewRequest returns an http.Request with information for the Exercism API.
41func (c *Client) NewRequest(method, url string, body io.Reader) (*http.Request, error) {
42 if c.Client == nil {
43 c.Client = HTTPClient
44 }
45
46 req, err := http.NewRequest(method, url, body)
47 if err != nil {
48 return nil, err
49 }
50
51 req.Header.Set("User-Agent", UserAgent)
52 if c.ContentType == "" {
53 req.Header.Set("Content-Type", "application/json")
54 } else {
55 req.Header.Set("Content-Type", c.ContentType)
56 }
57 if c.Token != "" {
58 req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", c.Token))
59 }
60
61 return req, nil
62}
63
64// Do performs an http.Request and optionally parses the response body into the given interface.
65func (c *Client) Do(req *http.Request) (*http.Response, error) {

Callers 9

submitMethod · 0.95
runDownloadFunction · 0.95
newDownloadFunction · 0.95
TestDoFunction · 0.95
TokenIsValidMethod · 0.95
IsPingableMethod · 0.95
downloadMethod · 0.80
TestDumpRequestFunction · 0.80

Calls

no outgoing calls

Tested by 3

TestDoFunction · 0.76
TestDumpRequestFunction · 0.64