DefineApiConfig
katanakit-js / defineApiConfig
Function: defineApiConfig()
Section titled “Function: defineApiConfig()”function defineApiConfig<T>(input): ConfigFacade<T>;Defined in: core/services/http.service.ts:543
Declares the API registry in a single call - the config-file entry point.
Registers every ApiEntry you list and returns them alongside the
props, flags and methods declared on the same literal, so one export default
is the whole setup: no second registration step.
Only object entries shaped like { baseUri, endpoints } reach the registry;
boolean flags are kept on config for your own methods to read.
Type Parameters
Section titled “Type Parameters”| Type Parameter | Description |
|---|---|
T extends object |
The literal passed in. |
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
input |
T & ThisType<ConfigFacade<T>> & ConfigValues<NoInfer<T>, ApiConfigValue> |
API entries, flags and methods in one object literal. |
Returns
Section titled “Returns”ConfigFacade<T>
The registered config plus the declared methods (see ConfigFacade).
Throws
Section titled “Throws”If a non-method value is an object that is not an API entry.
Example
Section titled “Example”import { defineApiConfig } from "katanakit-js";
export default defineApiConfig({ pokeapi: { baseUri: "https://pokeapi.co/api/v2", endpoints: { byId: "/pokemon/:id/" }, }, debug: true, getPokemon: async function () { return useFetch("pokeapi", "byId", { params: { id: 25 } }); },});Remarks
Section titled “Remarks”Methods must be written with function, not as arrows - this.config
is undefined inside an arrow function.