MCPcopy
hub / github.com/mislav/hub / GenericAPIRequest

Method GenericAPIRequest

github/client.go:858–889  ·  view source on GitHub ↗
(method, path string, data interface{}, headers map[string]string, ttl int)

Source from the content-addressed store, hash-verified

856}
857
858func (client *Client) GenericAPIRequest(method, path string, data interface{}, headers map[string]string, ttl int) (*simpleResponse, error) {
859 api, err := client.simpleApi()
860 if err != nil {
861 return nil, err
862 }
863 api.CacheTTL = ttl
864
865 var body io.Reader
866 switch d := data.(type) {
867 case map[string]interface{}:
868 if method == "GET" {
869 path = addQuery(path, d)
870 } else if len(d) > 0 {
871 json, err := json.Marshal(d)
872 if err != nil {
873 return nil, err
874 }
875 body = bytes.NewBuffer(json)
876 }
877 case io.Reader:
878 body = d
879 }
880
881 return api.performRequest(method, path, body, func(req *http.Request) {
882 if body != nil {
883 req.Header.Set("Content-Type", "application/json; charset=utf-8")
884 }
885 for key, value := range headers {
886 req.Header.Set(key, value)
887 }
888 })
889}
890
891// GraphQL facilitates performing a GraphQL request and parsing the response
892func (client *Client) GraphQL(query string, variables interface{}, data interface{}) error {

Callers 1

apiCommandFunction · 0.95

Calls 4

simpleApiMethod · 0.95
addQueryFunction · 0.85
performRequestMethod · 0.80
SetMethod · 0.45

Tested by

no test coverage detected