Skip to main content
Version: 3.x.x

Parameters


URL parameters

Url parameters are detected automatically thanks to typescript literal types, which makes it very convenient to manage them and detect possible regressions. The assumption is very simple, string parameters must consist of two parts : and a name, such as: :userId or :productId. We place them in the endpoint string when we initialize request.


Setting url parameters

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

const getUsers = client.createRequest()({ endpoint: "/users/:userId" });

const request = getUsers.setParams({ userId: 281 });
console.log(request.endpoint); // Output: "/users/281"
const getProduct = client.createRequest()({ endpoint: "/entities/:categoryId/:productId" });

const request = getProduct.setParams({ categoryId: 12, productId: "Z24PBW443" });
console.log(request.endpoint); // Output: "/entities/12/Z24PBW443"

Directly on send method

const getProduct = client.createRequest()({ endpoint: "/entities/:categoryId/:productId" });

const request = getProduct.send({ params: { categoryId: 12, productId: "Z24PBW443" } });
console.log(request.endpoint); // Output: "/entities/12/Z24PBW443"