Guide

Getting started with kuusi.

Getting started

Getting started with kuusi is really easy. Firstly, make sure you have the Deno runtime installed. Node.js, Bun and other runtimes are not supported. Secondly, run the init command to create the basic structure of your project.

deno run -Ar jsr:@kuusi/kuusi my-project

Here we are creating a new project called my-project.

Understanding kuusi

After you run the init command, your project looks something like this:

my-project/
├── deno.json  
├── deno.lock  
├── kuusi.config.ts  
├── routes  
│   └── index.source.ts  
└── src  
    └── index.ts  
  
3 directories, 5 files  

There are three important files to understand, src/index.ts, routes/index.source.ts and kuusi.config.ts.

routes/index.source.ts

This file, like all files in the routes are automatically imported and set up as route.

// Import the WebSource class to set up an endpoint
import { WebSource } from "@kuusi/kuusi";  
  
const route = new WebSource({  
  // Now define the logic for the GET method.  
  GET: () =>  
    // Return a response.  
    new Response(  
      JSON.stringify({  
        message: "Tervetuloa Kuusella!",  
      }),  
      {  
        status: 200,  
        headers: {  
          "content-type": "application/json; charset=utf-8",  
        },  
      },  
    ),  
});  
  
// Export the route as default  
export default route;  
  

This is a very basic route that returns a string as a response. This function does not use any of the parameters kuusi supplies (req: Request and urlPatternResult: URLPatternResult), but those can be used if you wish to.

kuusi.config.ts

This file is your projects entrypoint. Running this file starts kuusi.

// Import the KuusiConfig class from the types module.
import { KuusiConfig } from "@kuusi/kuusi/types";  
  
const config = new KuusiConfig({  
  // Configure kuusi here  
});  
  
// Export the config  
export default config;  
  

This file is used to configure kuusi however you wish. For more information on configuration, see the configuration docs.

src/index.ts

This file is your projects entrypoint. Running this file starts kuusi.

// Import the kuusi router and the routes collector
import { getKuusiRoutes, kuusi } from "@kuusi/kuusi";  
  
// Collect all the routes  
const routes = await getKuusiRoutes();  
  
// Set up a new server with Deno.serve and serve the port 1296  
Deno.serve({ port: 1296 }, async function (req) {  
  // Use the kuusi router  
  return await kuusi(req, routes);  
});  
  

This file is used to run the server. Since kuusi is only a router, and not a wrapper for a server, you can implement it in your own logic if you desire to do so.