Extend Your API
BreezeAPI Plugins
Enhance your API with official plugins that add powerful features with minimal configuration
CORS
Official
Enable Cross-Origin Resource Sharing (CORS) for your API with configurable options.
Installation
bun add @breezeapi/corsCRON
Official
Schedule tasks to run at specific intervals using CRON expressions.
Installation
bun add @breezeapi/cronExtend BreezeAPI
Create your own plugins
BreezeAPI offers tools to let you create your own plugins easier like a global config object.
- Hook into request/response lifecycle
- Add global middleware
- Extend core functionality
my-plugin.ts
import { Config, type apiRequest, type apiResponse, type apiNext } from '@breezeapi/core';
[...]
/**
* Zod schema for per-route cache configuration.
* - enabled: Enable or disable caching for this route.
* - cacheKey: Optional custom cache key. If not provided, the URL will be used.
* - duration: Cache duration in seconds.
*/
export const cacheConfigSchema = z.object({
enabled: z.boolean().default(true), // Caching active or not
cacheKey: z.string().optional(), // Optional cache key for custom cache key generation if nothing is provided, the URL will be used as the cache key
duration: z.string(), // Cache duration as a string (e.g. "5s", "2h")
});
/**
* Zod schema for global breezeCache configuration.
* - redisUrl: Redis connection URL (required).
* - enabled: Enable or disable caching globally.
* - excludedPaths: Optional array of route prefixes to exclude from caching.
* - debug: Optional flag to enable debug logging.
*/
export const breezeCacheConfigSchema = z.object({
redisUrl: z.string().url(), // required Redis URL
enabled: z.boolean().default(true), // Caching active or not
excludedPaths: z.array(z.string()).optional(), // Optional: excluded routes for caching
debug: z.boolean().optional(), // <-- Add debug flag
});
[...]
export function initializeCache() {
const BreezeConfig = Config.get('breezeCache');
const parseResult = breezeCacheConfigSchema.safeParse(BreezeConfig);
[...]
}