Skip to content

Commit

Permalink
docs: Update readme for builder initWith headers losing Content-Type
Browse files Browse the repository at this point in the history
Adding more documentation and a better default example of mapping to a builder by including the `"Content-Type" : "application/json"` header to avoid content type errors.
  • Loading branch information
gpickin committed Oct 19, 2022
1 parent 61cd00d commit 7a80b01
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -908,14 +908,17 @@ component {
.initWith(
baseUrl = "https://api.github.com",
headers = {
"Authorization" = getColdBox().getSetting( "SWAPI_TOKEN" )
"Content-Type" : "application/json", // If you map to a builder with headers - make sure you set your Content-Type if desired
"Authorization" = getColdBox().getSetting( "SWAPI_TOKEN" )
}
);
}

}
```

Note: If you are mapping a builder and use the `initWith( headers = {... } )`, these headers will overwrite the default headers you get with a HyperRequest so you might see some inconsistencies. A hyperRequest defaults the headers to `"Content-Type" : "application/json"`, so if you want to set a content-type, please include that in your headers struct, like above.

You can also set or change the defaults by either passing the key / value pairs in to the `init` method or by calling the appropriate `HyperRequest` method on the `HyperBuilder.defaults` property.

```js
Expand Down

0 comments on commit 7a80b01

Please sign in to comment.