Coder Social home page Coder Social logo

node-backlib-koa's Introduction

BaseKoa class with typescript decorators for routing based on koa and @koa/router

import Koa, { DefaultContext, DefaultState } from 'koa';
import { BaseRouter, routeGet } from '@backlib/koa';

//// EXAMPLE - BaseRouter for class/decorator style API
class Hello3 extends BaseRouter<DefaultState, DefaultContext>{
	#count = 0;

	@routeGet('hello3')
	async hello(ctx: DefaultContext) {
		this.#count++;
		ctx.body = {
			message: `Hello3 from server ${this.#count}`
		}
	}
}

async function main() {

	const app = new Koa();

	const hello3 = new Hello3('/api/');
	app.use(hello3.middleware());   
    
	app.listen(8080);    
}

// Now http://localhost:8080/api/hello3 will return {message: "Hello3 from server ..."}
  • Typed Build with typescript for typescript.
  • Modern Node.js 14 and above, compiled with native class fields and null coalescing native support.
  • Minimalist Not a framework, just some libs that can be assembled into an application infrastructure code.
  • PromiseAsync/Await centric Use Promise/async/await patterns for all async calls.
  • Web Async Web request utilities based on koajs over express as it is a modern rewrite of more or less the same API with backed in support for Promise/async/await (simplify many of the usecases)

node-backlib-koa's People

Contributors

jeremychone avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.