Skip to content

Commit

Permalink
Version Bump v2.1.0: Automatically add Content-Type: application/json…
Browse files Browse the repository at this point in the history
… when there is a request body
  • Loading branch information
thinkingserious committed Jun 11, 2016
1 parent eb3fcac commit eb041d6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions examples/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -155,7 +154,6 @@ func main() {
BaseURL: baseURL + "/" + apiKey,
Headers: Headers,
QueryParams: queryParams,
Body: Body,
}
response, err = rest.API(request)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit eb041d6

Please sign in to comment.