nextkit
TypeScript icon, indicating that this package has built-in type declarations

3.4.3 • Public • Published

nextkit

nextkit is a toolkit for Next.js apps that lets you generate type-safe, error handled Next.js API routes that conform to a standard response type.

Basic Usage

// @filename src/server.ts

const api = createAPI({
	async onError(req, res, error) {
		return {
			status: 500,
			message: error.message,
		};
	},

	async getContext(req, res) {
		return {
			time: Date.now(),
		};
	},
});

// @filename src/pages/api/time.ts
import {api} from '../../server';

export default api({
	async GET({ctx}) {
		return `You requested at ${ctx.time}`;
	},
});

Documentation

I plan to write documentation in the future. For now, you can find examples covering most features on the GitHub repository.

/nextkit/

    Package Sidebar

    Install

    npm i nextkit

    Weekly Downloads

    220

    Version

    3.4.3

    License

    Apache-2.0

    Unpacked Size

    28.1 kB

    Total Files

    9

    Last publish

    Collaborators

    • aabbccsmith