DEV Community

Cover image for Building Modern Backends with Kaapi: Introduction & Getting Started
ShyGyver
ShyGyver

Posted on • Edited on

Building Modern Backends with Kaapi: Introduction & Getting Started

Kaapi: A flexible, extensible backend framework for modern APIs with messaging, documentation, and type safety built right in.

This series is written for backend developers who love TypeScript and can appreciate Hapiโ€™s design philosophy.


What Is Kaapi?

Kaapi (@kaapi/kaapi) is a TypeScript-first backend framework built on top of Hapi.js.

It gives you a clean foundation for building modular, documented, and message-driven APIs without the boilerplate.

Think of it as Hapi, but with:

  • Type safety throughout
  • Messaging support (Kafka-ready)
  • Auto-generated OpenAPI & Postman docs
  • Built-in logging via Winston

So not "Yet again a new Nodejs framework this year!" in case your were thinking that (I know you did) but rather a practical evolution: the same trusted Hapi core, now supercharged.

Itโ€™s about cutting boilerplate, not reinventing the wheel.


โš™๏ธ Installation

Install it from npm:

npm install @kaapi/kaapi
Enter fullscreen mode Exit fullscreen mode

๐Ÿš€ Your First Kaapi Application

Kaapi is built on Hapi, so everything you know from Hapi still works; but Kaapi adds higher-level ergonomics.

Hereโ€™s the simplest working server:

import { Kaapi } from '@kaapi/kaapi';

const init = async () => {
  const app = new Kaapi({
    port: 3000,
    host: 'localhost',
  });

  await app.listen();
  app.log('๐Ÿš€ Server running at:', app.base().info.uri);
};

init();
Enter fullscreen mode Exit fullscreen mode
  • app.listen() starts the server
  • app.base() gives access to the underlying Hapi server

Routing

Routing feels familiar, declarative and type-safe:

app.route({
  method: 'GET',
  path: '/',
}, () => 'Hello World!');
Enter fullscreen mode Exit fullscreen mode

Want a custom 404? Just register an empty route config:

app.route({}, (req, h) => h.response('404 Not Found').code(404));
Enter fullscreen mode Exit fullscreen mode

The {} route acts as a global catch-all; simple and intuitive.


Logging Made Easy

Kaapi comes with Winston out of the box.

app.log.silly('This is mindless');
app.log.debug('Debugging');
app.log.info('Server started');
app.log.warn('This is a warning');
app.log.error('Something went wrong');
Enter fullscreen mode Exit fullscreen mode

Or define your own logger:

import winston from 'winston';
import { createLogger, Kaapi } from '@kaapi/kaapi';

const logger = createLogger({
  level: 'info',
  transports: [new winston.transports.Console()],
});

const app = new Kaapi({ logger });
Enter fullscreen mode Exit fullscreen mode

Built-in API Documentation

Kaapi automatically generates OpenAPI + Postman docs.
Once your server runs, open:

Everything comes from your routes and Joi validations; no manual Swagger config.

Example route:

import Joi from 'joi';

app.route<{ Query: { name: string } }>({
  method: 'GET',
  path: '/',
  options: {
    description: 'Greet someone',
    tags: ['Index'],
    validate: {
      query: Joi.object({
        name: Joi.string()
          .trim()
          .default('World')
          .description('Optional name to personalize the greeting response'),
      }),
    },
  },
}, ({ query: { name } }) => `Hello ${name}!`);
Enter fullscreen mode Exit fullscreen mode

Whatโ€™s Coming Next

This article is just the start of the Kaapi series.
In upcoming parts, weโ€™ll dive into the interesting subjects:

  • the configuration and documentation generation (OpenAPI, Postman, SwaggerUI)
  • Request data validation (with Arktype, Joi, Valibot, Zod)
  • Authentication with Auth Designs (Basic, API Key, OAuth2)
  • Messaging with Kafka and Event-Driven Architectures
  • Testing and Deployment Tips

๐Ÿ“ฆ Get started now

npm install @kaapi/kaapi
Enter fullscreen mode Exit fullscreen mode

๐Ÿ”— Learn more: github.com/demingongo/kaapi/wiki


Top comments (0)