npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

koa-eko

v1.0.2

Published

Create koa-router controllers using a decorator-based style

Downloads

7

Readme

KoaEko

Create koa-router controllers using a decorator-based style

What is KoaEko ?

KoaEko is koa module allowing you to generate koa-router controllers using decorators

Dependencies

KoaEko was built using multiple packages:

Installation

You can install KoaEko using npm:

npm i koa-eko

Reference

EkoController

KoaEko provides a EkoController you must inherit from if you want KoaEko to work

import { EkoController } from "koa-eko";

class MyController extends EkoController {}

Once your controller inherits from EkoController, it will have access to Routes(): IMiddleware and AllowedMethods(): IMiddleware. You can find more on these functions on koa-router documentation

Decorators

EkoVersion(version: string)

EkoVersion allows you to set a version for a KoaEko controller

import { EkoController, EkoVersion } from "koa-eko";

@EkoVersion("1.0.0")
class MyController extends EkoController {}

If the tag is missing, the version 1.0.0 will be used by default

EkoRoute(type: RouteType, path: string, name?: string, description?: string)

EkoRoute declares the attached method as a KoaEko controller route

  • type (RouteType): verb of the API route (eg: RouteType.GET)
  • path (string): the route relative path (eg: "/")
  • name (string) optional: the route name (eg: "Get all users")
  • description (string) optional: the route description (eg: "Returns all users with their personal informations")
import { IRouterContext } from "koa-router"
import { EkoController, EkoRoute, RouteType } from "koa-eko"

class UsersController extends EkoController {
    public constructor() {
        super();
    }
    
    @EkoRoute(RouteType.GET, "/" "Get all users", "Returns all users with their personal informations")
    public async MyGetRoute(ctx: IRouterContext): Promise<void> {
        // Do Stuff
    }
}

EkoGet(path: string, name?: string, description?: string)

Alias for EkoRoute(RouteType.GET, path, name, description)

import { IRouterContext } from "koa-router"
import { EkoGet } from "koa-eko"

@EkoGet("/" "Get all users", "Returns all users with their personal informations")
public async MyGetRoute(ctx: IRouterContext): Promise<void> {
    // Do Stuff
}

EkoPost(path: string, name?: string, description?: string)

Alias for EkoRoute(RouteType.POST, path, name, description)

import { IRouterContext } from "koa-router"
import { EkoPost } from "koa-eko"

@EkoPost("/" "Add an user", "Add a new user and return it")
public async MyPostRoute(ctx: IRouterContext): Promise<void> {
    // Do Stuff
}

EkoPut(path: string, name?: string, description?: string)

Alias for EkoRoute(RouteType.PUT, path, name, description)

import { IRouterContext } from "koa-router"
import { EkoPut } from "koa-eko"

@EkoPut("/{id}" "Patch an user", "Update user's informations")
public async MyPutRoute(ctx: IRouterContext): Promise<void> {
    // Do Stuff
}

EkoDelete(path: string, name?: string, description?: string)

Alias for EkoRoute(RouteType.DELETE, path, name, description)

import { IRouterContext } from "koa-router"
import { EkoDelete } from "koa-eko"

@EkoDelete("/{id}" "Delete an user", "Delete an existing user")
public async MyDeleteRoute(ctx: IRouterContext): Promise<void> {
    // Do Stuff
}

Enums

RouteType

RouteType represents the verbs that KoaEko handles.

export enum RouteType {
    GET = "GET",
    POST = "POST",
    PUT = "PUT",
    DELETE = "DELETE"
}

Exemple

Here is a controller build using KoaEko

import { IRouterContext } from "koa-router";
import { Comment } from "../../POCO/Comment";
import { EkoGet, EkoVersion } from "koa-eko";


@EkoVersion("1.0.0")
export class CommentsController extends EkoController {

    public constructor() {
        super();
    }

    @EkoGet("/", "Get all comments", "Get all comments and / or associated users")
    public async GetAll(ctx: IRouterContext): Promise<void> {
        let comments: Comment[] = await Comment.scope(this.getScope()).all();
        ctx.body = comments;
    }

}

export default new CommentsController();