POST, PUT, PATCH, DELETE
The method allows you to execute a Mutations without TanStack's QueryClient.
- With
baseUrl
- No
baseUrl
import { requestFn } from '@openapi-qraft/react';
const result = qraft.<service>.<operation>(
{
parameters,
baseUrl,
signal,
meta,
},
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
requestFn: RequestFn
- Required, a function that will be used to execute the request
const result = qraft.<service>.<operation>(
{
parameters,
signal,
meta,
},
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
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
import { requestFn } from '@openapi-qraft/react';
/**
* Executes the request:
* ###
* PATCH /posts/123
*
* { "title": "New title" }
**/
const posts = await qraft.posts.updatePost(
{
parameters: { path: { post_id: 123 } },
body: { title: 'New title' },
baseUrl: 'https://api.sandbox.monite.com/v1',
},
requestFn
);
import {
requestFn,
type RequestFnPayload,
type OperationSchema,
} from '@openapi-qraft/react';
/**
* Executes the request:
* ###
* PATCH /posts/123
*
* { "title": "New title" }
**/
const posts = await qraft.posts.updatePost(
{
parameters: { path: { post_id: 123 } },
body: { title: 'New title' },
},
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',
});