Skip to content

Commit

Permalink
Merge pull request #159 from mackerelio/revert-useful-json-request
Browse files Browse the repository at this point in the history
revert PostJSON, PutJSON
  • Loading branch information
yseto authored Jul 16, 2024
2 parents 5094607 + 6faebaa commit ebbc66f
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions mackerel.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,28 @@ func requestInternal[T any](client *Client, method, path string, params url.Valu
}
return &data, resp.Header, nil
}

func (c *Client) compatRequestJSON(method string, path string, payload interface{}) (*http.Response, error) {
var body bytes.Buffer
err := json.NewEncoder(&body).Encode(payload)
if err != nil {
return nil, err
}

req, err := http.NewRequest(method, c.urlFor(path, url.Values{}).String(), &body)
if err != nil {
return nil, err
}
req.Header.Add("Content-Type", "application/json")
return c.Request(req)
}

// Deprecated: use other prefered method.
func (c *Client) PostJSON(path string, payload interface{}) (*http.Response, error) {
return c.compatRequestJSON(http.MethodPost, path, payload)
}

// Deprecated: use other prefered method.
func (c *Client) PutJSON(path string, payload interface{}) (*http.Response, error) {
return c.compatRequestJSON(http.MethodPut, path, payload)
}

0 comments on commit ebbc66f

Please sign in to comment.