Skip to content

Each fetch client exposes path and href for building URLs without making a request - useful for navigation, <a> tags, or passing URLs to other services.

pages/example/index.tsx
ts
import fetchClients from "_/fetch";

const useFetch = fetchClients["users/[id]"];

useFetch.path([123]);
// → "/api/users/123"

useFetch.path([123], { query: { include: "posts" } });
// → "/api/users/123?include=posts"

useFetch.href("https://api.example.com", [123]);
// → "https://api.example.com/api/users/123"

useFetch.href("https://api.example.com", [123], { query: { include: "posts" } });
// → "https://api.example.com/api/users/123?include=posts"

Multiple parameters follow path order:

ts
// route: posts/[userId]/comments/[commentId]
useFetch.path([456, 789]);
// → "/api/posts/456/comments/789"

Released under the MIT License.