Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita0645b9

Browse files
committed
feat: fixed parsing of params and url, added debugging
1 parentfd9924a commita0645b9

File tree

7 files changed

+426
-67
lines changed

7 files changed

+426
-67
lines changed

‎.dist.eslintrc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
"no-empty": "off",
1818
"no-useless-escape": "off",
1919
"no-fallthrough": "off",
20-
"getter-return": "off"
20+
"getter-return": "off",
21+
"no-control-regex": "off",
22+
"no-cond-assign": "off"
2123
},
2224
"globals": {
2325
"regeneratorRuntime": "writable"

‎README.md

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ const Frisbee = require('frisbee');
184184

185185
*`Frisbee` - accepts an`options` object, with the following accepted options:
186186

187-
*`baseURI` - the default URI to use as a prefix for all HTTP requests (optional as of v2.0.4+)
187+
*`baseURI`(String)- the default URI to use as a prefix for all HTTP requests (optional as of v2.0.4+)
188188

189189
* If your API server is running on`http://localhost:8080`, then use that as the value for this option
190190

@@ -202,19 +202,47 @@ const Frisbee = require('frisbee');
202202

203203
* Using [React Native][react-native]? You might want to readthis article about [automaticIP configuration][automatic-ip-configuration].
204204

205-
*`headers`- an object containing default headers to sendwith every request
205+
*`headers`(Object)- an object containing default headers to sendwith every request
206206

207207
***Tip**: You'll most likely want to set the `"Accept"` header to `"application/json"` and the `"Content-Type"` header to `"application/json"`
208208
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+
209213
* `auth` - will call the `auth()` function below and set it as a default
210214
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+)
212232

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
214234

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
216236

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)
218246
219247
Upon being invoked, `Frisbee` returns an object with the following chainable methods:
220248
@@ -238,9 +266,15 @@ Upon being invoked, `Frisbee` returns an object with the following chainable met
238266
239267
* `path` **required** - the path for the HTTP request (e.g. `/v1/login`, will be prefixed with the value of `baseURI` if set)
240268
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]
242270

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):
244278

245279
* To turn off caching, pass`cache: 'reload'` to native fetch options:
246280

@@ -267,6 +301,7 @@ Upon being invoked, `Frisbee` returns an object with the following chainable met
267301
*`api.post(path, options)`-POST
268302
*`api.put(path, options)`-PUT
269303
*`api.del(path, options)`-DELETE
304+
*`api.delete(path, options)`-DELETE
270305
*`api.options(path, options)`-OPTIONS (_does not currently work- see tests_)
271306
*`api.patch(path, options)`-PATCH
272307

@@ -316,7 +351,7 @@ Upon being invoked, `Frisbee` returns an object with the following chainable met
316351

317352
### Debugging
318353

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][].
320355

321356
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).
322357

@@ -533,3 +568,5 @@ Therefore we created `frisbee` to serve as our API glue, and hopefully it'll ser
533568
[xhook]: https://github.com/jpillora/xhook
534569

535570
[cabin]: https://cabinjs.com
571+
572+
[fetch-documentation]: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch

‎package.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,14 @@
4141
"dependencies": {
4242
"@babel/runtime":"^7.4.5",
4343
"abortcontroller-polyfill":"^1.3.0",
44+
"boolean":"^1.0.0",
4445
"caseless":"^0.12.0",
4546
"common-tags":"^1.8.0",
4647
"cross-fetch":"^3.0.3",
48+
"debug":"^4.1.1",
4749
"qs":"^6.7.0",
48-
"url-join":"^4.0.0"
50+
"url-join":"^4.0.0",
51+
"url-parse":"^1.4.7"
4952
},
5053
"devDependencies": {
5154
"@babel/cli":"^7.4.4",
@@ -179,6 +182,12 @@
179182
],
180183
"ignore": [
181184
"config.js"
182-
]
185+
],
186+
"rules": {
187+
"complexity": [
188+
"error",
189+
38
190+
]
191+
}
183192
}
184193
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp