Skip to content

What is Switchblade?

Switchblade is Javascript backend abstraction layer to allow developers to create APIs equpped with various features and also make it easy to switch between different backend frameworks like Hono, Express, and Fastify.


The core philosophy of Switchblade:

Key Features

  • 🛡️ Comprehensive input validation
  • 🔀 Adapter-based architecture
  • 📄 Automatic OpenAPI generation
  • 🚀 TypeScript-first design

Supported Validation Libraries

  • Zod
  • TypeBox
  • Valibot (Coming Soon)

Got a better validation library? Open an issue or PR on GitHub

Supported Adapters

  • Hono
  • Express (Coming Soon)
  • Fastify (Coming Soon)

Got a better adapter? Open an issue or PR on GitHub

Quick Example

typescript
import { Switchblade } from "@takodotid/switchblade";
import { createHonoAdapter } from "@takodotid/switchblade/adapters/hono";
import { z } from "zod";
import { serve } from "@hono/node-server";

const app = new Switchblade();

app.post(
    "/users",
    (req, res) => {
        const { name, email } = req.body;

        return res.status(200).json({
            id: crypto.randomUUID(),
            name,
            email,
        });
    },
    {
        body: {
            content: {
                "application/json": z.object({
                    name: z.string(),
                    email: z.string().email(),
                }),
            },
        },
        response: {
            200: {
                content: {
                    "application/json": z.object({
                        id: z.number(),
                        name: z.string(),
                        email: z.string().email(),
                    }),
                },
            },
        },
    }
);

const hono = createHonoAdapter(app);

serve(
    {
        fetch: hono.fetch,
        port: 3000,
    },
    () => console.log("Server running on http://localhost:3000")
);

Released under the MIT License.