API reference
Endpoint members
Everything a built endpoint carries.
Calling
useQuery(request?, options?) => UseQueryResult<TData, HapiError>
- Available on GET endpoints with every required path parameter bound;
neverotherwise. optionsis TanStack’s own option type with the error channel pinned.selectmay reshape the result.
useSuspenseQuery(request?, options?) => UseSuspenseQueryResult<TData, HapiError>
- As above, for Suspense.
datais never undefined.
useMutation(options?) => UseMutationResult<TResp, HapiError, TReq> & { abort() }
- Available whenever path parameters are bound, including on GET endpoints.
abort()stops the attempt in flight. Cancellation on unmount requireswithOptions({ cancelOnUnmount: true }).
useInfiniteQuery(request?, options?) => UseInfiniteQueryResult<InfiniteData<TResp>, HapiError>
- Present only when
getNextPageParamwas declared.
fetch(request?, options?: { signal?, timeout? }) => Promise<TResp>
- Runs the full pipeline with no React involved. Rejects with a
HapiError. - The options bag is present on every arity, so a bound endpoint can still be cancelled.
Composing
queryOptions(request?) => HapiTaggedQueryOptions<TResp>
- Feed this to
useQueries,prefetchQuery, orfetchQuery. - Its
queryKeycarries TanStack’sDataTag, sogetQueryDatareturns the response type instead ofunknown.
mutationOptions(options?) => HapiMutationOptions<TResp, TReq>
- For composing a mutation outside a component.
queryKey / mutationKeyReadonlyArray<unknown>
- The key for the current bindings:
[...prefix, service, endpoint, resolvedPath, params?]. - Deliberately untagged, because it is used as an invalidation prefix as often as a whole key.
queryKeyFor / mutationKeyFor(request?) => ReadonlyArray<unknown>
- The key that a specific request would produce, without calling it.
resolvedConfig() => { method, path, url, headers, params, pathParams }
- What this endpoint would send right now. Useful in tests and logs.
urlincludes the origin;pathdoes not.
Chaining
Each of these returns a new endpoint. The original is never mutated.
| Method | Binds |
|---|---|
| withParams(p) | Request parameters, partially or fully |
| withPathParams(p) | Path parameters — unlocks capabilities |
| withOptions(o) | staleTime, timeout, cancelOnUnmount, queryKeyPrefix, any TanStack option |
| withHeaders(h) | A record or an async provider |
| onRequest, onResponse, onHttpError, onError, … | A lifecycle hook |