Skip to content

Commit

Permalink
Add headers/content/body methods and better options type.
Browse files Browse the repository at this point in the history
  • Loading branch information
elbywan committed Sep 22, 2017
1 parent 906e5e5 commit de5f740
Show file tree
Hide file tree
Showing 12 changed files with 130 additions and 34 deletions.
32 changes: 30 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<a href="https://coveralls.io/github/elbywan/wretch?branch=master"><img src="https://coveralls.io/repos/github/elbywan/wretch/badge.svg?branch=master" alt="Coverage Status" /></a>
</h1>
<h4 align="center">
A tiny (&lt; 1.3Kb g-zipped) wrapper built around fetch with an intuitive syntax.
A tiny (&lt; 1.4Kb g-zipped) wrapper built around fetch with an intuitive syntax.
</h4>
<h5 align="center">
<i>f[ETCH] [WR]apper</i>
Expand Down Expand Up @@ -308,18 +308,46 @@ w = w.query({ c: 3, d : [4, 5] })
// url is now http://example.com?c=3&d=4&d=5
```
#### accept(what: string)
#### headers(headerValues: { [headerName: string]: any })
Set request headers.
```js
wretch("...")
.headers({ "Content-Type": "text/plain", Accept: "application/json" })
.body("my text")
.post()
.json()
```
#### accept(headerValue: string)
Shortcut to set the "Accept" header.
```js
wretch("...").accept("application/json")
```
#### content(headerValue: string)
Shortcut to set the "Content-Type" header.
```js
wretch("...").content("application/json")
```
## Body Types
*A body type is only needed when performing put/patch/post requests with a body.*
#### body(contents: any) {
Set the request body with any content.
```js
wretch("...").body("hello").put()
```
#### json(jsObject: Object)
Sets the content type header, stringifies an object and sets the request body.
Expand Down
2 changes: 1 addition & 1 deletion dist/bundle/wretch.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit de5f740

Please sign in to comment.