Opkit is a TypeScript server library that allows you to easily create operation-based APIs.
This project is work-in-progress. Not all code is uploaded to this repository yet.
You define your operations together with their input and output schemas.
Opkit then turns them into an HTTP server with:
- runtime validation of all input and output data
- an OpenAPI declaration for automatic client generation
- interactive documentation
- standardised error handling
- customisable logging
export const PreheatOven = defineOperation({
name: 'PreheatOven',
description: 'This operation starts preheating the pizza oven.',
input: z.object({
targetTemperature: z.number().describe('The desired temperature at the end of preheating.'),
unit: z.enum(['celsius', 'fahrenheit']),
}),
output: z.object({
estimatedPreheatDoneTime: z.iso.datetime(),
}),
group: 'Baking',
requiresApiKey: true,
handler: async function ({ targetTemperature, unit }, metaParameter) {
// your handler code goes here
return {
estimatedPreheatDoneTime: new Date('2025-11-12T01:23:45Z').toISOString(),
};
},
});