Skip to content

DefineApiConfig

katanakit-js / 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 Parameter Description
T extends object The literal passed in.
Parameter Type Description
input T & ThisType<ConfigFacade<T>> & ConfigValues<NoInfer<T>, ApiConfigValue> API entries, flags and methods in one object literal.

ConfigFacade<T>

The registered config plus the declared methods (see ConfigFacade).

If a non-method value is an object that is not an API entry.

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 } });
},
});

Methods must be written with function, not as arrows - this.config is undefined inside an arrow function.