Skip to main content
Version: 4.x.x

Query Params


Request query parameters

The use of query params is based on built-in parser. We can freely change its options and format to match our needs.


Setting query params

You can set query params by using the setQueryParams method on request. It's type can be configured on request creation.

type QueryParamsType = {
search: string;
sort: string;
};

const getUsers = client.createRequest<Response, void, void, QueryParamsType>()({ endpoint: "/users" });

// Setting the query params

const request = getUsers.setQueryParams({ search: "John", sort: "age" });
console.log(request.endpoint); // Output: "/users?search=John&sort=age"
const getUsers = client.createRequest<Response, void, void, string>()({ endpoint: "/users" });

const request = getUsers.setQueryParams("search=John&sort=age");
console.log(request.endpoint); // Output: "/users?search=John&sort=age"

Custom query params format

We can setup custom config with instructions how to stringify the values. It can be setup on the client with setQueryParamsConfig method.

Available options:

{
arrayFormat: bracket | index | comma | separator | bracket-separator | none;
arraySeparator: string;
dateParser: (value: QueryParamType) => string;
encode: boolean;
objectParser: (value: QueryParamType) => string;
skipEmptyString: boolean;
skipNull: boolean;
strict: boolean;
}