diff --git a/CHANGELOG.md b/CHANGELOG.md index 462f0ca..2d45a13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [2.1.0] - 2016-06-10 +### Added +- Automatically add Content-Type: application/json when there is a request body + ## [2.0.0] - 2016-06-03 ### Changed - Made the Request and Response variables non-redundant. e.g. request.RequestBody becomes request.Body diff --git a/examples/example.go b/examples/example.go index dcbf965..404c191 100644 --- a/examples/example.go +++ b/examples/example.go @@ -17,7 +17,6 @@ func main() { // Build the request headers key := os.Getenv("SENDGRID_API_KEY") Headers := make(map[string]string) - Headers["Content-Type"] = "application/json" Headers["Authorization"] = "Bearer " + key // GET Collection @@ -155,7 +154,6 @@ func main() { BaseURL: baseURL + "/" + apiKey, Headers: Headers, QueryParams: queryParams, - Body: Body, } response, err = rest.API(request) if err != nil { diff --git a/rest.go b/rest.go index ae8a514..d8aef1b 100644 --- a/rest.go +++ b/rest.go @@ -51,6 +51,9 @@ func BuildRequestObject(request Request) (*http.Request, error) { for key, value := range request.Headers { req.Header.Set(key, value) } + if len(request.Body) > 0 { + req.Header.Set("Content-Type", "application/json") + } return req, err }