You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
* Using [React Native][react-native]? You might want to readthis article about [automaticIP configuration][automatic-ip-configuration].
204
204
205
-
*`headers`- an object containing default headers to sendwith every request
205
+
*`headers`(Object)- an object containing default headers to sendwith every request
206
206
207
207
***Tip**: You'll most likely want to set the `"Accept"` header to `"application/json"` and the `"Content-Type"` header to `"application/json"`
208
208
209
+
* `body` (Object) - an object containing default body payload to send with every request (API method specific `params` options will override or extend properties defined here, but not deep merge)
210
+
211
+
* `params` (Object) an object containing default querystring parameters to send with every request (API method specific `params` options will override or extend properties defined here, but will not deep merge)
212
+
209
213
* `auth` - will call the `auth()` function below and set it as a default
210
214
211
-
* `arrayFormat` - how to stringify array in passed body. See [qs][qs-url] for available formats
215
+
* `parse` - options passed to `qs.parse` method (see [qs][qs-url] for all available options)
216
+
217
+
* `ignoreQueryPrefix` (Boolean) - defaults to `true`, and parses querystrings from URL's properly
218
+
219
+
*`stringify`- options passed to`qs.stringify`method (see [qs][qs-url]for all available options)
220
+
221
+
*`addQueryPrefix` (Boolean)- defaults to`true`, and affixes the pathwith required`?` parameterif a querystring is to be passed
222
+
223
+
*`format` (String)- defaults to`RFC1738`
224
+
225
+
*`arrayFormat` (String)- defaults to`'indices'`
226
+
227
+
*`preventBodyOnMethods` (Array)- defaults to`[ 'GET', 'HEAD', 'DELETE', 'CONNECT' ]`, and is anArrayofHTTP method names that we will convert a`body` option to be querystringifiedURLparameters (e.g.`api.get('/v1/users', { search: 'foo' })` will resultin`GET /v1/users?search=foo`).According to [RFC7231](https://tools.ietf.org/html/rfc7231), the default methods defined here have no defined semantics for having a payload body, and having one may cause some implementations to reject the request (which is why we set this as a default). If you wish to disable this, you may pass `preventBodyOnMethods: false` or your own custom Array `preventBodyOnMethods: [ ... ]`
228
+
229
+
*`interceptableMethods` (Array)- defaults to allAPI methods supportedbelow (defaults to`GET`,`HEAD`,`POST`,`PUT`,`DELETE`,`OPTIONS`,`PATCH`)
230
+
231
+
*`raw` (Boolean)-return a raw fetchresponse (newasof v2.0.4+)
212
232
213
-
* `raw` - return a raw fetch response (new as of v2.0.4+)
233
+
*`abortToken` (Symbol)- someSymbol that you can use to abort one or more frisbee requests
214
234
215
-
* `abortToken` - some Symbol that you can usetoabort one or more frisbee requests
235
+
*`signal` (Object)- an [AbortController](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) Signal usedtocancel a fetch request
216
236
217
-
* `signal` - an [AbortController](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) Signal used to cancel a fetch request
237
+
*`mode` (String)- passed to fetch, defaults to"same-origin" (see [Fetch's documentation][fetch-documentation] for more info)
238
+
239
+
* `cache` (String) - passed to fetch, defaults to "default" (see [Fetch's documentation][fetch-documentation]for more info)
240
+
241
+
*`credentials` (String)- passed to fetch, defaults to"same-origin" (see [Fetch's documentation][fetch-documentation] for more info)
242
+
243
+
* `redirect` (String) - passed to fetch, defaults to "follow" (see [Fetch's documentation][fetch-documentation]for more info)
244
+
245
+
*`referrer` (String)- passed to fetch, defaults to"client" (see [Fetch's documentation][fetch-documentation] for more info)
218
246
219
247
Upon being invoked, `Frisbee` returns an object with the following chainable methods:
220
248
@@ -238,9 +266,15 @@ Upon being invoked, `Frisbee` returns an object with the following chainable met
238
266
239
267
* `path` **required** - the path for the HTTP request (e.g. `/v1/login`, will be prefixed with the value of `baseURI` if set)
240
268
241
-
* `options` _optional_ - an object containing options, such as header values, a request body, form data, or a querystring to send along with the request. For the `GET` method (and the `DELETE` method as of version `1.3.0`), `body` data will be encoded in the query string.**This `options` object is passed to the native Fetch API method, which means you can use native Fetch API method options as well fromhere <https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch>**
269
+
* `options` _optional_ - an object containing options, such as header values, a request body, form data, or a querystring to send along with the request.These options by default are inherited from global options passed to `new Frisbee({ options })`.For the `GET` method (and the `DELETE` method as of version `1.3.0`), `body` data will be encoded in the query string.\*\*This `options` object is passed to the native Fetch API method, which means you can use native Fetch API method options as well from[Fetch's documentation][fetch-documentation]
242
270
243
-
Here are a few examples (you can override/merge your set default headers as well per request):
271
+
> To make only a certain request be raw and not parsed by Frisbee:
272
+
273
+
```js
274
+
const res = await api.get('/v1/messages', { raw: false });
275
+
```
276
+
277
+
> Here are a fewexamples (you can override/merge your set default headers as well per request):
244
278
245
279
* To turn off caching, pass`cache: 'reload'` to native fetch options:
246
280
@@ -267,6 +301,7 @@ Upon being invoked, `Frisbee` returns an object with the following chainable met
267
301
*`api.post(path, options)`-POST
268
302
*`api.put(path, options)`-PUT
269
303
*`api.del(path, options)`-DELETE
304
+
*`api.delete(path, options)`-DELETE
270
305
*`api.options(path, options)`-OPTIONS (_does not currently work- see tests_)
271
306
*`api.patch(path, options)`-PATCH
272
307
@@ -316,7 +351,7 @@ Upon being invoked, `Frisbee` returns an object with the following chainable met
316
351
317
352
### Debugging
318
353
319
-
Ifyou want to debug request and responses, we recommend to use [xhook][].
354
+
Out of the boxyoucan run your application with `DEBUG=frisbee node app.js` to output debug logging with Frisbee, but if youwant to further debug request and responses, we recommend to use [xhook][].
320
355
321
356
We also **highly recommend** to [use CabinJS as your Node.js and JavaScript logging utility][cabin] (see [Automatic Request Logging](https://cabinjs.com/#/?id=automatic-request-logging) for complete examples).
322
357
@@ -533,3 +568,5 @@ Therefore we created `frisbee` to serve as our API glue, and hopefully it'll ser