Skip to content

Commit

Permalink
🔥 Make .query() chainable #20
Browse files Browse the repository at this point in the history
  • Loading branch information
elbywan committed May 24, 2018
1 parent b53cca3 commit 1a6a7c8
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 36 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,19 +285,24 @@ await blogs.url(`/${id}`).delete().res()
const noMoreBlogs = blogs.url("http://mywebsite.org/", true)
```

#### query(qp: object | string)
#### query(qp: object | string, replace: boolean)

Converts a javascript object to query parameters, then appends this query string to the current url. String values are used as the query string verbatim.
Converts a javascript object to query parameters, then appends this query string to the current url.
String values are used as the query string verbatim.

Pass `true` as the second argument to replace existing query parameters.

```js
let w = wretch("http://example.com")
// url is http://example.com
w = w.query({ a: 1, b: 2 })
// url is now http://example.com?a=1&b=2
w = w.query({ c: 3, d: [4, 5] })
// url is now http://example.com?c=3&d=4&d=5
// url is now http://example.com?a=1&b=2c=3&d=4&d=5
w = w.query("five&six&seven=eight")
// url is now http://example.com?five&six&seven=eight
// url is now http://example.com?a=1&b=2c=3&d=4&d=5&five&six&seven=eight
w = w.query({ reset: true }, true)
// url is now http://example.com?reset=true
```

#### options(options: Object, mixin: boolean = true)
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.

12 changes: 10 additions & 2 deletions dist/wretcher.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,22 @@ export declare class Wretcher {
* Converts a javascript object to query parameters,
* then appends this query string to the current url.
*
* If given a string, use the string as the query verbatim.
*
* ```
* let w = wretch("http://example.com") // url is http://example.com
*
* // Chain query calls
* w = w.query({ a: 1, b : 2 }) // url is now http://example.com?a=1&b=2
* w = w.query("foo-bar-baz-woz") // url is now http://example.com?a=1&b=2&foo-bar-baz-woz
*
* // Pass true as the second argument to replace existing query parameters
* w = w.query("c=3&d=4", true) // url is now http://example.com?c=3&d=4
* ```
*
* @param qp An object which will be converted.
* @param qp An object which will be converted, or a string which will be used verbatim.
*/
query(qp: object): Wretcher;
query(qp: object | string, clear?: boolean): Wretcher;
/**
* Set request headers.
* @param headerValues An object containing header keys and values
Expand Down
59 changes: 41 additions & 18 deletions 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 1a6a7c8

Please sign in to comment.