GET, HEAD, OPTIONS
The method allows you to execute a Queries without TanStack's QueryClient.
- With
baseUrl - No
baseUrl
import { requestFn } from '@openapi-qraft/react';
const result = qraft.<service>.<operation>(
{
parameters,
baseUrl,
signal,
meta,
queryKey,
},
requestFn
);
Arguments​
-
parameters: { path, query, header } | {}- Required, OpenAPI request parameters for the query, strictly-typed ✨
- If operation does not require parameters, you must pass an empty object
{}for strictness
- If operation does not require parameters, you must pass an empty object
baseUrl- Required base URL for therequestFnsignal- An optionalAbortSignalto cancel the requestmeta- An optional object that will be passed to therequestFnqueryKey: QueryKeycould be provided instead ofparameters
- Required, OpenAPI request parameters for the query, strictly-typed ✨
requestFn: RequestFn- Required, a function that will be used to execute the request
const result = qraft.<service>.<operation>(
{
parameters,
signal,
meta,
queryKey,
},
requestFn
);
Arguments​
-
parameters: { path, query, header } | {}- Required, OpenAPI request parameters for the query, strictly-typed ✨
- If operation does not require parameters, you must pass an empty object
{}for strictness
- If operation does not require parameters, you must pass an empty object
- Required, OpenAPI request parameters for the query, strictly-typed ✨
signal- An optionalAbortSignalto cancel the requestmeta- An optional object that will be passed to therequestFnqueryKey: QueryKeycould be provided instead ofparameters
requestFn: Omit<RequestFn, 'baseUrl'>- Required, a function that will be used to execute the request. Note,
that
baseUrlwill not be provided in therequestFn.
- Required, a function that will be used to execute the request. Note,
that
Returns​
result: Promise<T> - The result of the query execution
Examples​
- With
baseUrl - No
baseUrl - With
queryKey
import { requestFn } from '@openapi-qraft/react';
/**
* Executes the request:
* ###
* GET /posts?limit=10
**/
const posts = await qraft.posts.getPosts(
{
parameters: { query: { limit: 10 } },
baseUrl: 'https://api.sandbox.monite.com/v1',
},
requestFn
);
import {
requestFn,
type RequestFnPayload,
type OperationSchema
} from '@openapi-qraft/react';
/**
* Executes the request:
* ###
* GET /posts?limit=10
**/
const posts = await qraft.posts.getPosts(
{
parameters: { query: { limit: 10 } },
},
customRequestFn
);
/**
* Custom request function with the predefined base URL
**/
const customRequestFn = async <T,>(
requestSchema: OperationSchema,
requestInfo: Omit<RequestFnPayload, 'baseUrl'>
): Promise<T> =>
requestFn(requestSchema, {
...requestInfo,
baseUrl: 'https://api.sandbox.monite.com/v1',
});
import { requestFn } from '@openapi-qraft/react';
/**
* Executes the request:
* ###
* GET /posts?limit=10
**/
const posts = await qraft.posts.getPosts(
{
queryKey: qraft.posts.getPosts.getQueryKey({ query: { limit: 10 } }),
baseUrl: 'https://api.sandbox.monite.com/v1',
},
requestFn
);