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
baseUrl
- Required base URL for therequestFn
signal
- An optionalAbortSignal
to cancel the requestmeta
- An optional object that will be passed to therequestFn
queryKey: QueryKey
could be provided instead ofparameters
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
signal
- An optionalAbortSignal
to cancel the requestmeta
- An optional object that will be passed to therequestFn
queryKey: QueryKey
could be provided instead ofparameters
requestFn: Omit<RequestFn, 'baseUrl'>
- Required, a function that will be used to execute the request. Note,
that
baseUrl
will 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
);