@izara_frontend/remote-endpoint
v1.0.6
Published
create standard frontend query endpoint
Readme
@izara_frontend/remote-endpoint
A utility library for dynamically constructing RTK Query (Redux Toolkit Query) endpoints, automatically resolving base URLs from the global Redux store (rootConfigSlice).
Installation & Import
Import the creation functions from the package entry point:
import {
createGetEndpoint,
createQueryEndpoint,
createMutationEndpoint,
createWebsocketEndpoint,
createStandardEndpoint
} from "@izara_frontend/remote-endpoint";API Documentation & Examples
1. createGetEndpoint
Generates a GET endpoint for retrieving a versioned object instance using its serviceTag and objectType.
Signature
function createGetEndpoint(
objType: { serviceTag: string; objectType: string },
options?: { customCacheKey?: object }
): object | null;Real Code Example
Used in objReducer.js to fetch table layouts and definitions:
const mainObjType = {
serviceTag: "TableConfig",
objectType: "tableConfig",
};
export const getTableConfigEndpoint = createGetEndpoint(mainObjType);2. createQueryEndpoint
Creates a generic query endpoint (typically HTTP POST) with a configurable URL path, method, and query options.
Signature
function createQueryEndpoint(
baseUrlLocations: string[],
endpointName: string,
pathParams: string,
method: string,
options?: { customCacheKey?: object }
): object | null;Real Code Example
Used in objReducer.js to fetch sorted search results:
export const getSortResultData = createQueryEndpoint(
["rootConfig", "endpoints", "sortResultsEndpoint", "getSortResultData"],
"getSortResultData",
"SortedResults/ProcessItemsPerPagePagination/ProcessItemsPerPagePagination",
"POST",
{
customCacheKey: {
onQueryStarted: async (
cacheQuery,
{ getCacheEntry, dispatch, queryFulfilled, getState }
) => {
try {
const { data } = await queryFulfilled;
// Process and upsert results into the global store
} catch (error) {
console.error("Query failed:", error);
}
},
},
}
);3. createMutationEndpoint
Generates a mutation endpoint to modify data on the server with custom actions and methods.
Signature
function createMutationEndpoint(
baseUrlLocations: string[],
endpointName: string,
pathParams: string,
method: string,
onQueryStarted?: object
): object | null;Real Code Example
Used in userDetailSlice.js to setup/initialize user settings:
const baseUrlLocationsAccount = [
"rootConfig",
"endpoints",
"userAccountEndpoint",
"userDetailAccount",
];
const create_UserDetailAccount_userDetailAccount = createMutationEndpoint(
baseUrlLocationsAccount,
"create_UserDetailAccount_userDetailAccount",
"setupNewUser",
"POST",
onQueryStarted
);4. createWebsocketEndpoint
Constructs a WebSocket connection mutation that handles raw socket connections and streams/messages directly.
Signature
function createWebsocketEndpoint(
baseUrlLocations: string[],
endpointName: string,
pathParams: string,
type?: "query" | "mutation"
): object | null;Real Code Example
Used in objReducer.js to initiate search query pipelines over WebSockets:
const userId = localStorage.getItem("base_user_id") || "superUserA";
export const sendSortResultMain = createWebsocketEndpoint(
["rootConfig", "endpoints", "sortResultsEndpoint", "sortResultMainWebsocket"],
"sendSortResultMain",
"Test/?userId=" + userId + "&submittedByUserId=" + userId,
"mutation"
);5. createStandardEndpoint
Creates a generic standardized placeholder endpoint query/mutation meant for raw caching or manual queries.
Signature
function createStandardEndpoint(
endpoint: { name: string; type: "query" | "mutation" | "S3" }
): object | null;Real Code Example
Used in objReducer.js to define and register the cache schema for sortResultData:
export const usageApiList = [
createStandardEndpoint({ name: "sortResultData", type: "query" }),
// Injects sortResultData into global state without triggering outbound calls
];