Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revert PostJSON, PutJSON #159

Merged
merged 1 commit into from
Jul 16, 2024
Merged

revert PostJSON, PutJSON #159

merged 1 commit into from
Jul 16, 2024

Conversation

yseto
Copy link
Contributor

@yseto yseto commented Jul 16, 2024

refer https://github.com/mackerelio/mackerel-client-go/releases/tag/v0.27.0

// PostJSON shortcut method for posting json
func (c *Client) PostJSON(path string, payload interface{}) (*http.Response, error) {
return c.requestJSON("POST", path, payload)
}
// PutJSON shortcut method for putting json
func (c *Client) PutJSON(path string, payload interface{}) (*http.Response, error) {
return c.requestJSON("PUT", path, payload)
}
func (c *Client) requestJSON(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).String(), &body)
if err != nil {
return nil, err
}
req.Header.Add("Content-Type", "application/json")
return c.Request(req)
}

@yseto yseto self-assigned this Jul 16, 2024
@yseto yseto merged commit ebbc66f into master Jul 16, 2024
10 checks passed
@yseto
Copy link
Contributor Author

yseto commented Jul 16, 2024

thanks your review.

@yseto yseto deleted the revert-useful-json-request branch July 16, 2024 03:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants