params()
Function Signature
params: (params: DenchURLSearchParams) => R
type DenchURLSearchParams = ConstructorParameters<typeof URLSearchParams>[0]
Description
params() accepts URL query parameter input in the request builder chain.
The accepted values are the same values supported by the URLSearchParams constructor.
string | string[][] | Record<string, string> | URLSearchParams | undefined
Example
import { dench } from 'dench-fetch';
const api = dench('https://api.example.com');
const users = await api
.get('/users')
.params({ page: '1', limit: '20' })
.toJson();
String query parameters can also be passed.
const users = await api
.get('/users')
.params('?page=1&limit=20')
.toJson();
Notes
params()was added in0.1.0-beta.7.- The current implementation converts the provided value to
URLSearchParams, but does not yet apply it to the final request URL. - Until that limitation is removed, include the query string directly in the API path when the request needs actual query parameters.
const users = await api
.get('/users?page=1&limit=20')
.toJson();