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; never otherwise.
  • options is TanStack’s own option type with the error channel pinned. select may reshape the result.

useSuspenseQuery(request?, options?) => UseSuspenseQueryResult<TData, HapiError>

  • As above, for Suspense. data is 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 requires withOptions({ cancelOnUnmount: true }).

useInfiniteQuery(request?, options?) => UseInfiniteQueryResult<InfiniteData<TResp>, HapiError>

  • Present only when getNextPageParam was 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, or fetchQuery.
  • Its queryKey carries TanStack’s DataTag, so getQueryData returns the response type instead of unknown.

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.
  • url includes the origin; path does not.

Chaining

Each of these returns a new endpoint. The original is never mutated.

MethodBinds
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