Skip to content

Commit

Permalink
🏭 Add auth method to set the Authorization header.
Browse files Browse the repository at this point in the history
  • Loading branch information
elbywan committed Oct 13, 2017
1 parent e37ea0b commit 1694396
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 8 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ Creates a new Wretcher object with an url and [vanilla fetch options](https://de

*Helper methods are optional and can be chained.*

| [url](#urlurl-string-replace-boolean--false) | [query](#queryqp-object) | [options](#optionsoptions-object-mixin-boolean--true) | [headers](#headersheadervalues-object) | [accept](#acceptheadervalue-string) | [content](#contentheadervalue-string) | [catcher](#catchererrorid-number--string-catcher-error-wretchererror--void) | [defaults](#defaultsopts-object-mixin-boolean--false) | [errorType](#errortypemethod-text--json--text) | [polyfills](#polyfillspolyfills-object) |
|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|
| [url](#urlurl-string-replace-boolean--false) | [query](#queryqp-object) | [options](#optionsoptions-object-mixin-boolean--true) | [headers](#headersheadervalues-object) | [accept](#acceptheadervalue-string) | [content](#contentheadervalue-string) | [auth](#authheadervalue-string) | [catcher](#catchererrorid-number--string-catcher-error-wretchererror--void) | [defaults](#defaultsopts-object-mixin-boolean--false) | [errorType](#errortypemethod-text--json--text) | [polyfills](#polyfillspolyfills-object) |
|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|

#### url(url: string, replace: boolean = false)

Expand Down Expand Up @@ -362,6 +362,14 @@ Shortcut to set the "Content-Type" header.
wretch("...").content("application/json")
```

#### auth(headerValue: string)

Shortcut to set the "Authorization" header.

```js
wretch("...").auth("Basic d3JldGNoOnJvY2tz")
```

#### catcher(errorId: number | string, catcher: (error: WretcherError) => void)

Adds a [catcher](https://github.com/elbywan/wretch#catchers) which will be called on every subsequent request error.
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.

2 changes: 1 addition & 1 deletion dist/bundle/wretch.js.map

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion dist/wretcher.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export declare class Wretcher {
/**
* Returns a new Wretcher object with the argument url appended and the same options.
* @param url String url
* @param replace Boolean it true, replaces the current url instead of appending
* @param replace Boolean If true, replaces the current url instead of appending
*/
url(url: string, replace?: boolean): Wretcher;
/**
Expand Down Expand Up @@ -75,6 +75,11 @@ export declare class Wretcher {
* @param headerValue Header value
*/
content(headerValue: string): Wretcher;
/**
* Shortcut to set the "Authorization" header.
* @param headerValue Header value
*/
auth(headerValue: string): Wretcher;
/**
* Adds a default catcher which will be called on every subsequent request error when the error code matches.
* @param errorId Error code or name
Expand Down
9 changes: 8 additions & 1 deletion dist/wretcher.js

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

Loading

0 comments on commit 1694396

Please sign in to comment.