Skip to content

Commit

Permalink
Merge pull request #1 from moment-team/more-default-options
Browse files Browse the repository at this point in the history
More configurable default options for fetch
  • Loading branch information
henit committed Feb 18, 2020
2 parents 5c2d6e5 + ba5b8ff commit c8465e0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
25 changes: 14 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,17 +243,20 @@ Make HTTP Request

**Options:**

Property | Type | Description
--- | --- | ---
`baseUrl` | *string* | Base url to the root of the target API/resource
`headers` | *object* | Headers ({ [name]: contents })
`method` | *string* | Request method
`path` | *string* | Path (under baseUrl) to the endpoint
`query` | *object* | URL query parameters
`body` | *object* | Request body
`credentials` | *string* | Credential option: `omit`, `same-origin`, or `include` (default)
`contentType` | *string* | Shortcut for setting the Content-Type header

Property | Type | Description
--- | --- | ---
`baseUrl` | *string* | Base url to the root of the target API/resource
`headers` | *object* | Headers ({ [name]: contents })
`method` | *string* | Request method
`path` | *string* | Path (under baseUrl) to the endpoint
`query` | *object* | URL query parameters
`body` | *object* | Request body
`credentials` | *string* | Credential option: `omit`, `same-origin`, or `include` (default)
`contentType` | *string* | Shortcut for setting the Content-Type header
`cache` | *string* | `no-cache`, `reload`, `force-cache`, `only-if-cached`, `default` (default)
`redirect` | *string* | `manual`, `error`, `follow` (default)
`referrerPolicy`| *string* | `no-referrer`, `client` (default)
`mode` | *string* | `no-cors`, `same-origin`, `cors` (default)
**Examples:**

```
Expand Down
10 changes: 9 additions & 1 deletion src/Http.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ Http.request = async (options = {}) => {
query = {},
body,
credentials = 'include',
contentType = 'application/json'
contentType = 'application/json',
cache = 'default',
redirect = 'follow',
referrerPolicy = 'client',
mode = 'cors'
} = options;

const url = baseUrl
Expand Down Expand Up @@ -55,6 +59,10 @@ Http.request = async (options = {}) => {
headers: fetchHeaders,
method,
credentials,
cache,
redirect,
referrerPolicy,
mode,
body: (contentType && contentType.includes('json')) ? fetchBody : body
});

Expand Down

0 comments on commit c8465e0

Please sign in to comment.