# nextkit

By [Alistair Smith](https://paragraph.com/@alistair-smith) · 2021-11-01

---

`nextkit` is a library for building e2e type-safe API routes for Next.js. I built it after frustration that I could not get strongly typed API routes in the client side. Inspired by [trpc](https://trpc.io), I decided to create something similar.

nextkit works by defining a type-safe router where each http method has a single return type. We can then take the _type_ of said router and import that into the frontend. This works fine and we never import any serverside code because we do the following

    import type ProductsAPI from '../pages/api/product';
    
    type Res = InferAPIResponseType<typeof ProductsAPI, 'GET'>;
    

So this works because we use a nice feature of TypeScript called “type only” imports.

---

*Originally published on [Alistair Smith](https://paragraph.com/@alistair-smith/nextkit)*
