{"repo":"ivandotv/nextjs-koa-api","free":true,"listed":false,"github":"https://github.com/ivandotv/nextjs-koa-api","clone":"git clone https://github.com/ivandotv/nextjs-koa-api.git","description":"Koa.js framework setup to run within Next.js API routes.","language":"TypeScript","stars":11,"topics":["koa-router","koajs","nextjs","nextjs-api","nextjs-api-routes"],"license":"MIT","category":"api-integrations-sdks","readme_excerpt":"Next.js Koa API - Introduction - Motivation - Why Koa - Installation - Usage - Routing - Attaching a custom router - Nextjs request and response objects - Body data - Typescript - Testing - Example - License - Api Docs Introduction Nextjs Koa API is a library that packages Koa.js framework for use with the Next.js API routes. Motivation Using Next.js routes is pretty straightforward, however, doing something like REST API with CRUD routes requires a more complicated setup. You end up using the switch statement to check which http method is used and then which url is requested, and soon you end up with a spaghetti code in your API route that is hard to maintain and test. It would be great if we could use tried and tested HTTP framework directly inside the routes. So I decided to set up Koa.js to run inside the Next.js API route. Why Koa There are a lot of frameworks in Node.js land for handling HTTP responses, I've decided on Koa.js because it supports async middleware out of the box. And the way the middleware is run via the onion model is superior to other frameworks. Koa.js source is very small and it can be initialized fast, which is important for a serverless function. Installation Usage This library bundles Koa.js and Koa router in one easy to use class. It is important to note that nothing is changed in regards to working with Koa or Koa Router. The simplest example that would mimic the original Next.js api router is this: KoaApi class extends Koa so all Koa methods are","default_branch":null,"files":null,"tree":[],"storefront":"/r/ivandotv","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/ivandotv/nextjs-koa-api/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}